2012/8/30 <[email protected]>:
> Author: markt
> Date: Thu Aug 30 19:44:46 2012
> New Revision: 1379091
>
> URL: http://svn.apache.org/viewvc?rev=1379091&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/tc7.0.x/trunk/ (props changed)
> tomcat/tc7.0.x/trunk/java/org/apache/el/parser/AstValue.java
> tomcat/tc7.0.x/trunk/test/org/apache/el/TestMethodExpressionImpl.java
>
> Propchange: tomcat/tc7.0.x/trunk/
> ------------------------------------------------------------------------------
> Merged /tomcat/trunk:r1379090
>
> Modified: tomcat/tc7.0.x/trunk/java/org/apache/el/parser/AstValue.java
> URL:
> http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/el/parser/AstValue.java?rev=1379091&r1=1379090&r2=1379091&view=diff
> ==============================================================================
> --- tomcat/tc7.0.x/trunk/java/org/apache/el/parser/AstValue.java (original)
> +++ tomcat/tc7.0.x/trunk/java/org/apache/el/parser/AstValue.java Thu Aug 30
> 19:44:46 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);
The above was previously called before calling resolver.getValue(),
but now it is not called neither before resolver.invoke(), nor before
resolver.getValue().
> + 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/tc7.0.x/trunk/test/org/apache/el/TestMethodExpressionImpl.java
> URL:
> http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/test/org/apache/el/TestMethodExpressionImpl.java?rev=1379091&r1=1379090&r2=1379091&view=diff
> ==============================================================================
> --- tomcat/tc7.0.x/trunk/test/org/apache/el/TestMethodExpressionImpl.java
> (original)
> +++ tomcat/tc7.0.x/trunk/test/org/apache/el/TestMethodExpressionImpl.java Thu
> Aug 30 19:44:46 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: [email protected]
> For additional commands, e-mail: [email protected]
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]