Uploaded image for project: 'Commons OGNL'
  1. Commons OGNL
  2. OGNL-117

Compiled OGNL using bracket notation caches the result type of previous inner expression without #this

Attach filesAttach ScreenshotAdd voteVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Bug
    • Status: Reopened
    • Major
    • Resolution: Unresolved
    • 2.7.1
    • 4.0.x
    • ExpressionCompiler
    • None
    • 2.7.1-20070723.185910-9

    Description

      OGNL-105 (which is fixed). Executing expression object[propertyKey] causes ClassCastException when executed the second time with a propertyKey evaluating to a result of different type; it seems OGNL cached the result of the previous evaluation. The same works correctly when using #this, i.e. objectthis.propertyKey. The following test case demonstrates the problem:

      package test;

      import java.util.HashMap;

      import java.util.Map;

      import org.apache.tapestry.services.impl.OgnlClassResolver;

      import junit.framework.TestCase;

      import ognl.ClassResolver;

      import ognl.Node;

      import ognl.Ognl;

      import ognl.OgnlContext;

      import ognl.OgnlException;

      import ognl.enhance.ExpressionAccessor;

      public class OgnlTest extends TestCase {

      private Map map;

      private TestObject testObject = new TestObject("propertyValue");

      private String propertyKey = "property";

      public class TestObject {

      private String property;

      private Integer integerProperty = 1;

      public TestObject(String property)

      { this.property = property; }

      public String getProperty()

      { return property; }

      public Integer getIntegerProperty()

      { return integerProperty; }

      }

      public Map getMap()

      { return map; }

      public String getKey()

      { return "key"; }

      public TestObject getObject()

      { return testObject; }

      public String getPropertyKey()

      { return propertyKey; }

      public void testEnhancedOgnl() throws Exception

      { map = new HashMap(); map.put("key", "value"); ClassResolver ognlResolver = new OgnlClassResolver(); OgnlContext context = (OgnlContext)Ognl.createDefaultContext(this, ognlResolver); // Succeeds context = (OgnlContext)Ognl.createDefaultContext(this, ognlResolver); Node expression = Ognl.compileExpression(context, this, "object[#this.propertyKey]"); assertEquals("propertyValue", Ognl.getValue(expression.getAccessor(), context, this)) ; // Succeeds with 2.7.1-20070723.185910-9 context = (OgnlContext)Ognl.createDefaultContext(this, ognlResolver); Node expression2 = Ognl.compileExpression(context, this, "object[propertyKey]"); assertEquals("propertyValue", Ognl.getValue(expression2.getAccessor(), context, this)) ; propertyKey = "integerProperty"; // Succeeds assertEquals(1, Ognl.getValue(expression.getAccessor(), context, this)) ; // Fails with 2.7.1-20070723.185910-9 assertEquals(1, Ognl.getValue(expression2.getAccessor(), context, this)) ; }

      }

      Attachments

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            jkuhnert Jesse Kuhnert
            kaosko Kalle Korhonen

            Dates

              Created:
              Updated:

              Issue deployment