aboutsummaryrefslogtreecommitdiff
path: root/velocity-engine-core/src
diff options
context:
space:
mode:
authorClaude Brisson <cbrisson@apache.org>2016-11-09 22:11:56 +0000
committerClaude Brisson <cbrisson@apache.org>2016-11-09 22:11:56 +0000
commit01ebe9c07482c861a2a30f2fe2e0ce2b85182a2d (patch)
treef970610023cbf64be3fd02b65a66246b62fab304 /velocity-engine-core/src
parent6e445bba1cc198dd6e1dc6680ff58957589fda4b (diff)
downloadapache-velocity-engine-01ebe9c07482c861a2a30f2fe2e0ce2b85182a2d.tar.gz
[engine] fix an introspection bug for null argument (and add corresponding test case)
git-svn-id: https://svn.apache.org/repos/asf/velocity/engine/trunk@1769021 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'velocity-engine-core/src')
-rw-r--r--velocity-engine-core/src/main/java/org/apache/velocity/util/introspection/MethodMap.java5
-rw-r--r--velocity-engine-core/src/test/java/org/apache/velocity/test/util/introspection/UberspectImplTestCase.java28
2 files changed, 31 insertions, 2 deletions
diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/util/introspection/MethodMap.java b/velocity-engine-core/src/main/java/org/apache/velocity/util/introspection/MethodMap.java
index 2e5380e2..693ca671 100644
--- a/velocity-engine-core/src/main/java/org/apache/velocity/util/introspection/MethodMap.java
+++ b/velocity-engine-core/src/main/java/org/apache/velocity/util/introspection/MethodMap.java
@@ -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;
}
/**
diff --git a/velocity-engine-core/src/test/java/org/apache/velocity/test/util/introspection/UberspectImplTestCase.java b/velocity-engine-core/src/test/java/org/apache/velocity/test/util/introspection/UberspectImplTestCase.java
index cc0993f7..1f8acd58 100644
--- a/velocity-engine-core/src/test/java/org/apache/velocity/test/util/introspection/UberspectImplTestCase.java
+++ b/velocity-engine-core/src/test/java/org/apache/velocity/test/util/introspection/UberspectImplTestCase.java
@@ -126,4 +126,32 @@ public class UberspectImplTestCase extends BaseTestCase
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");
+ }
}