You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2012/08/30 21:43:26 UTC
svn commit: r1379090 - in /tomcat/trunk:
java/org/apache/el/parser/AstValue.java
test/org/apache/el/TestMethodExpressionImpl.java
Author: markt
Date: Thu Aug 30 19:43:26 2012
New Revision: 1379090
URL: http://svn.apache.org/viewvc?rev=1379090&view=rev
Log:
Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=53792
Support method expressions that include a method call that is not at the end of the expression
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=1379090&r1=1379089&r2=1379090&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/el/parser/AstValue.java (original)
+++ tomcat/trunk/java/org/apache/el/parser/AstValue.java Thu Aug 30 19:43:26 2012
@@ -103,39 +103,52 @@ public final class AstValue extends Simp
Object property = null;
int propCount = this.jjtGetNumChildren();
- if (propCount > 2 &&
- this.jjtGetChild(propCount - 1) instanceof AstMethodParameters) {
- // Method call with paramaters.
- propCount-=2;
- } else {
- propCount--;
- }
int i = 1;
-
- // evaluate any properties before our target
+ // Evaluate any properties or methods before our target
ELResolver resolver = ctx.getELResolver();
- if (propCount > 1) {
- while (base != null && i < propCount) {
- property = this.children[i].getValue(ctx);
+ while (i < propCount) {
+ if (i + 2 < propCount &&
+ this.children[i + 1] instanceof AstMethodParameters) {
+ // Method call not at end of expression
+ base = resolver.invoke(ctx, base,
+ this.children[i].getValue(ctx), null,
+ ((AstMethodParameters)
+ this.children[i + 1]).getParameters(ctx));
+ i += 2;
+ } else if (i + 2 == propCount &&
+ this.children[i + 1] instanceof AstMethodParameters) {
+ // Method call at end of expression
ctx.setPropertyResolved(false);
+ property = this.children[i].getValue(ctx);
+ i += 2;
+
+ if (property == null) {
+ throw new PropertyNotFoundException(MessageFactory.get(
+ "error.unreachable.property", property));
+ }
+ } else if (i + 1 < propCount) {
+ // Object with property not at end of expression
+ property = this.children[i].getValue(ctx);
base = resolver.getValue(ctx, base, property);
i++;
+
+ } else {
+ // Object with property at end of expression
+ ctx.setPropertyResolved(false);
+ property = this.children[i].getValue(ctx);
+ i++;
+
+ if (property == null) {
+ throw new PropertyNotFoundException(MessageFactory.get(
+ "error.unreachable.property", property));
+ }
}
- // if we are in this block, we have more properties to resolve,
- // but our base was null
- if (base == null || property == null) {
+ if (base == null) {
throw new PropertyNotFoundException(MessageFactory.get(
"error.unreachable.property", property));
}
}
- property = this.children[i].getValue(ctx);
-
- if (property == null) {
- throw new PropertyNotFoundException(MessageFactory.get(
- "error.unreachable.property", this.children[i]));
- }
-
Target t = new Target();
t.base = base;
t.property = property;
Modified: tomcat/trunk/test/org/apache/el/TestMethodExpressionImpl.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/el/TestMethodExpressionImpl.java?rev=1379090&r1=1379089&r2=1379090&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/el/TestMethodExpressionImpl.java (original)
+++ tomcat/trunk/test/org/apache/el/TestMethodExpressionImpl.java Thu Aug 30 19:43:26 2012
@@ -38,6 +38,7 @@ public class TestMethodExpressionImpl {
private ExpressionFactory factory;
private ELContext context;
+ private TesterBeanB beanB;
@Before
public void setUp() {
@@ -59,7 +60,7 @@ public class TestMethodExpressionImpl {
context.getVariableMapper().setVariable("beanAAA",
factory.createValueExpression(beanAAA, TesterBeanAAA.class));
- TesterBeanB beanB = new TesterBeanB();
+ beanB = new TesterBeanB();
beanB.setName("B");
context.getVariableMapper().setVariable("beanB",
factory.createValueExpression(beanB, TesterBeanB.class));
@@ -466,4 +467,13 @@ public class TestMethodExpressionImpl {
Integer actual = (Integer) ve.getValue(context);
assertEquals(Integer.valueOf(BUG53792.length()), actual);
}
+
+
+ @Test
+ public void testBug53792c() {
+ MethodExpression me = factory.createMethodExpression(context,
+ "#{beanB.sayHello().length()}", null, new Class<?>[] {});
+ Integer result = (Integer) me.invoke(context, null);
+ assertEquals(beanB.sayHello().length(), result.intValue());
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org