You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Lukasz Lenart (JIRA)" <ji...@apache.org> on 2013/12/31 14:24:50 UTC

[jira] [Updated] (OGNL-117) Compiled OGNL using bracket notation caches the result type of previous inner expression without #this

     [ https://issues.apache.org/jira/browse/OGNL-117?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Lukasz Lenart updated OGNL-117:
-------------------------------

    Fix Version/s:     (was: 2.7.3)
                   4.0.x

> Compiled OGNL using bracket notation caches the result type of previous inner expression without #this
> ------------------------------------------------------------------------------------------------------
>
>                 Key: OGNL-117
>                 URL: https://issues.apache.org/jira/browse/OGNL-117
>             Project: Commons OGNL
>          Issue Type: Bug
>          Components: ExpressionCompiler
>    Affects Versions: 2.7.1
>         Environment: 2.7.1-20070723.185910-9
>            Reporter: Kalle Korhonen
>            Assignee: Jesse Kuhnert
>             Fix For: 4.0.x
>
>
> 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. object[#this.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)) ;
> 	}
> }



--
This message was sent by Atlassian JIRA
(v6.1.5#6160)