Author: markt
Date: Mon Apr 27 23:01:16 2015
New Revision: 1676393
URL: http://svn.apache.org/r1676393
Log:
Add some comments to clarify behaviour.
Review by schultz re object allocation
Modified:
tomcat/trunk/java/org/apache/el/parser/AstValue.java
tomcat/trunk/test/org/apache/el/TestMethodExpressionImpl.java
Modified: tomcat/trunk/java/org/apache/el/parser/AstValue.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/el/parser/AstValue.java?rev=1676393&r1=1676392&r2=1676393&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/el/parser/AstValue.java (original)
+++ tomcat/trunk/java/org/apache/el/parser/AstValue.java Mon Apr 27 23:01:16
2015
@@ -41,6 +41,9 @@ import org.apache.el.util.ReflectionUtil
*/
public final class AstValue extends SimpleNode {
+ private static final Object[] EMPTY_ARRAY = new Object[0];
+ private static final Object[] ARRAY_OF_SINGLE_NULL = new Object[1];
+
protected static class Target {
protected Object base;
@@ -263,7 +266,8 @@ public final class AstValue extends Simp
private Object[] convertArgs(EvaluationContext ctx, Object[] src, Method
m) {
Class<?>[] types = m.getParameterTypes();
if (types.length == 0) {
- return new Object[0];
+ // Treated as if parameters have been provided so src is ignored
+ return EMPTY_ARRAY;
}
int paramCount = types.length;
@@ -271,23 +275,24 @@ public final class AstValue extends Simp
if (m.isVarArgs() && paramCount > 1 && (src == null || paramCount >
src.length) ||
!m.isVarArgs() && (paramCount > 0 && src == null ||
src != null && src.length != paramCount)) {
- String inputParamCount = null;
+ String srcCount = null;
if (src != null) {
- inputParamCount = Integer.toString(src.length);
+ srcCount = Integer.toString(src.length);
}
String msg;
if (m.isVarArgs()) {
msg = MessageFactory.get("error.invoke.tooFewParams",
- m.getName(), inputParamCount,
Integer.toString(paramCount));
+ m.getName(), srcCount, Integer.toString(paramCount));
} else {
msg = MessageFactory.get("error.invoke.wrongParams",
- m.getName(), inputParamCount,
Integer.toString(paramCount));
+ m.getName(), srcCount, Integer.toString(paramCount));
}
throw new IllegalArgumentException(msg);
}
if (src == null) {
- return new Object[1];
+ // Must be a varargs method with a single parameter.
+ return ARRAY_OF_SINGLE_NULL;
}
Object[] dest = new Object[paramCount];
Modified: tomcat/trunk/test/org/apache/el/TestMethodExpressionImpl.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/el/TestMethodExpressionImpl.java?rev=1676393&r1=1676392&r2=1676393&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/el/TestMethodExpressionImpl.java (original)
+++ tomcat/trunk/test/org/apache/el/TestMethodExpressionImpl.java Mon Apr 27
23:01:16 2015
@@ -467,6 +467,15 @@ public class TestMethodExpressionImpl {
@Test
+ public void testBug53792d() {
+ MethodExpression me = factory.createMethodExpression(context,
+ "#{beanB.sayHello().length()}", null, new Class<?>[] {});
+ Integer result = (Integer) me.invoke(context, new Object[] { "foo" });
+ assertEquals(beanB.sayHello().length(), result.intValue());
+ }
+
+
+ @Test
public void testBug56797a() {
MethodExpression me = factory.createMethodExpression(context,
"${beanAA.echo1('Hello World!')}", null , null);
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]