velocity-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cbris...@apache.org
Subject svn commit: r1769021 - in /velocity/engine/trunk/velocity-engine-core/src: main/java/org/apache/velocity/util/introspection/MethodMap.java test/java/org/apache/velocity/test/util/introspection/UberspectImplTestCase.java
Date Wed, 09 Nov 2016 22:11:56 GMT
Author: cbrisson
Date: Wed Nov  9 22:11:56 2016
New Revision: 1769021

URL: http://svn.apache.org/viewvc?rev=1769021&view=rev
Log:
[engine] fix an introspection bug for null argument (and add corresponding test case)

Modified:
    velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/util/introspection/MethodMap.java
    velocity/engine/trunk/velocity-engine-core/src/test/java/org/apache/velocity/test/util/introspection/UberspectImplTestCase.java

Modified: velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/util/introspection/MethodMap.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/util/introspection/MethodMap.java?rev=1769021&r1=1769020&r2=1769021&view=diff
==============================================================================
--- velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/util/introspection/MethodMap.java
(original)
+++ velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/util/introspection/MethodMap.java
Wed Nov  9 22:11:56 2016
@@ -462,6 +462,7 @@ public class MethodMap
                     return false;
                 }
             }
+            return true;
         }
         else if (methodArgs.length > 0) // more arguments given than the method accepts;
check for varargs
         {
@@ -490,9 +491,9 @@ public class MethodMap
                     return false;
                 }
             }
+            return true;
         }
-
-        return true;
+        return false;
     }
 
     /**

Modified: velocity/engine/trunk/velocity-engine-core/src/test/java/org/apache/velocity/test/util/introspection/UberspectImplTestCase.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/test/java/org/apache/velocity/test/util/introspection/UberspectImplTestCase.java?rev=1769021&r1=1769020&r2=1769021&view=diff
==============================================================================
--- velocity/engine/trunk/velocity-engine-core/src/test/java/org/apache/velocity/test/util/introspection/UberspectImplTestCase.java
(original)
+++ velocity/engine/trunk/velocity-engine-core/src/test/java/org/apache/velocity/test/util/introspection/UberspectImplTestCase.java
Wed Nov  9 22:11:56 2016
@@ -126,4 +126,32 @@ public class UberspectImplTestCase exten
             return Arrays.asList("1", "2", "3").iterator();
         }
     }
+
+    public class OverloadedMethods
+    {
+        public String foo() { return "foo0"; }
+        public String foo(String arg1) { return "foo1"; }
+        public String foo(String arg1, String arg2) { return "foo2"; }
+    }
+
+    public void testOverloadedMethods()
+    {
+        VelocityContext context = new VelocityContext();
+        context.put("over", new OverloadedMethods());
+        StringWriter writer = new StringWriter();
+        Velocity.evaluate(context, writer, "test", "$over.foo()");
+        assertEquals(writer.toString(), "foo0");
+        writer = new StringWriter();
+        Velocity.evaluate(context, writer, "test", "$over.foo('a')");
+        assertEquals(writer.toString(), "foo1");
+        writer = new StringWriter();
+        Velocity.evaluate(context, writer, "test", "$over.foo($null)");
+        assertEquals(writer.toString(), "foo1");
+        writer = new StringWriter();
+        Velocity.evaluate(context, writer, "test", "$over.foo('a', 'b')");
+        assertEquals(writer.toString(), "foo2");
+        writer = new StringWriter();
+        Velocity.evaluate(context, writer, "test", "$over.foo('a', $null)");
+        assertEquals(writer.toString(), "foo2");
+    }
 }



Mime
View raw message