Commits

jkuh...@d4b077e3-5828-0410-b394-cb2b42183085  committed bfee758

FIxes OGNL-117 by detecting attempts to use reflective indexed property accessor and throwing unsupported exceptions when found.

  • Participants
  • Parent commits 9d036c2

Comments (0)

Files changed (3)

   </component>
   <component name="ChangeListManager">
     <list default="true" name="Default" comment="">
-      <change type="MODIFICATION" beforePath="$PROJECT_DIR$/src/java/ognl/ASTAdd.java" afterPath="$PROJECT_DIR$/src/java/ognl/ASTAdd.java" />
-      <change type="MODIFICATION" beforePath="$PROJECT_DIR$/src/java/ognl/OgnlOps.java" afterPath="$PROJECT_DIR$/src/java/ognl/OgnlOps.java" />
+      <change type="MODIFICATION" beforePath="$PROJECT_DIR$/src/java/ognl/ObjectPropertyAccessor.java" afterPath="$PROJECT_DIR$/src/java/ognl/ObjectPropertyAccessor.java" />
+      <change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/src/test/java/org/ognl/test/SelfReferenceReflectionTest.java" />
       <change type="MODIFICATION" beforePath="$PROJECT_DIR$/OGNL.iws" afterPath="$PROJECT_DIR$/OGNL.iws" />
-      <change type="MODIFICATION" beforePath="$PROJECT_DIR$/src/test/java/org/ognl/test/objects/Indexed.java" afterPath="$PROJECT_DIR$/src/test/java/org/ognl/test/objects/Indexed.java" />
-      <change type="MODIFICATION" beforePath="$PROJECT_DIR$/src/test/java/org/ognl/test/IndexedPropertyTest.java" afterPath="$PROJECT_DIR$/src/test/java/org/ognl/test/IndexedPropertyTest.java" />
     </list>
   </component>
   <component name="ChangesViewManager" flattened_view="true" show_ignored="false" />
           <option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
         </PATH_ELEMENT>
       </PATH>
+      <PATH>
+        <PATH_ELEMENT>
+          <option name="myItemId" value="OGNL" />
+          <option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.ProjectViewProjectNode" />
+        </PATH_ELEMENT>
+        <PATH_ELEMENT>
+          <option name="myItemId" value="OGNL" />
+          <option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.ProjectViewModuleNode" />
+        </PATH_ELEMENT>
+        <PATH_ELEMENT>
+          <option name="myItemId" value="PsiDirectory:$PROJECT_DIR$" />
+          <option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
+        </PATH_ELEMENT>
+        <PATH_ELEMENT>
+          <option name="myItemId" value="PsiDirectory:$PROJECT_DIR$/src" />
+          <option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
+        </PATH_ELEMENT>
+      </PATH>
     </subPane>
   </component>
   <component name="ProjectReloadState">
     <option name="referencePos" value="0" />
     <option name="showLabels" value="true" />
   </component>
-  <component name="RunManager" selected="JUnit.IndexedPropertyTest">
-    <tempConfiguration default="false" name="IndexedPropertyTest" type="JUnit" factoryName="JUnit" enabled="false" merge="false">
+  <component name="RunManager" selected="JUnit.SelfReferenceReflectionTest">
+    <tempConfiguration default="false" name="SelfReferenceReflectionTest" type="JUnit" factoryName="JUnit" enabled="false" merge="false">
       <pattern value="org.ognl.test.*" />
       <module name="OGNL" />
       <option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
       <option name="ALTERNATIVE_JRE_PATH" value="/usr/local/jdk1.6.0_02" />
       <option name="PACKAGE_NAME" value="org.ognl.test" />
-      <option name="MAIN_CLASS_NAME" value="org.ognl.test.IndexedPropertyTest" />
+      <option name="MAIN_CLASS_NAME" value="org.ognl.test.SelfReferenceReflectionTest" />
       <option name="METHOD_NAME" value="" />
       <option name="TEST_OBJECT" value="class" />
       <option name="VM_PARAMETERS" value="" />
       </method>
     </configuration>
     <list size="1">
-      <item index="0" class="java.lang.String" itemvalue="JUnit.IndexedPropertyTest" />
+      <item index="0" class="java.lang.String" itemvalue="JUnit.SelfReferenceReflectionTest" />
     </list>
     <configuration default="true" type="#com.intellij.j2ee.web.tomcat.TomcatRunConfigurationFactory" factoryName="Local">
       <option name="WORKING_DIRECTORY" />
     <option name="myLastEditedConfigurable" />
   </component>
   <component name="editorHistoryManager">
-    <entry file="file://$PROJECT_DIR$/src/java/ognl/ASTOr.java">
-      <provider selected="true" editor-type-id="text-editor">
-        <state line="102" column="0" selection-start="3725" selection-end="3725" vertical-scroll-proportion="0.39923954">
-          <folding />
-        </state>
-      </provider>
-    </entry>
-    <entry file="file://$PROJECT_DIR$/src/java/ognl/ASTNotEq.java">
-      <provider selected="true" editor-type-id="text-editor">
-        <state line="51" column="8" selection-start="2268" selection-end="2268" vertical-scroll-proportion="0.41825095">
-          <folding />
-        </state>
-      </provider>
-    </entry>
-    <entry file="file://$PROJECT_DIR$/src/java/ognl/ObjectPropertyAccessor.java">
-      <provider selected="true" editor-type-id="text-editor">
-        <state line="70" column="8" selection-start="3076" selection-end="3076" vertical-scroll-proportion="0.49429658">
-          <folding />
-        </state>
-      </provider>
-    </entry>
-    <entry file="file://$PROJECT_DIR$/src/java/ognl/OgnlParser.java">
-      <provider selected="true" editor-type-id="text-editor">
-        <state line="2006" column="32" selection-start="68979" selection-end="68979" vertical-scroll-proportion="0.39147288">
-          <folding />
-        </state>
-      </provider>
-    </entry>
-    <entry file="file://$PROJECT_DIR$/src/java/ognl/ASTProperty.java">
-      <provider selected="true" editor-type-id="text-editor">
-        <state line="351" column="0" selection-start="14379" selection-end="14379" vertical-scroll-proportion="0.41825095">
-          <folding />
-        </state>
-      </provider>
-    </entry>
-    <entry file="file://$PROJECT_DIR$/src/java/ognl/enhance/ExpressionCompiler.java">
-      <provider selected="true" editor-type-id="text-editor">
-        <state line="726" column="48" selection-start="26086" selection-end="26086" vertical-scroll-proportion="0.6169687">
-          <folding />
-        </state>
-      </provider>
-    </entry>
-    <entry file="file://$PROJECT_DIR$/src/java/ognl/enhance/OgnlExpressionCompiler.java">
-      <provider selected="true" editor-type-id="text-editor">
-        <state line="85" column="0" selection-start="3608" selection-end="3608" vertical-scroll-proportion="0.39456344">
-          <folding />
-        </state>
-      </provider>
-    </entry>
-    <entry file="file://$PROJECT_DIR$/build.properties">
-      <provider selected="true" editor-type-id="text-editor">
-        <state line="2" column="15" selection-start="43" selection-end="43" vertical-scroll-proportion="0.024711696">
-          <folding />
-        </state>
-      </provider>
-    </entry>
-    <entry file="file://$PROJECT_DIR$/src/test/java/org/ognl/test/IndexedPropertyTest.java">
-      <provider selected="true" editor-type-id="text-editor">
-        <state line="89" column="0" selection-start="4594" selection-end="4594" vertical-scroll-proportion="1.0259434">
-          <folding />
-        </state>
-      </provider>
-    </entry>
-    <entry file="file://$PROJECT_DIR$/src/test/java/org/ognl/test/objects/Indexed.java">
-      <provider selected="true" editor-type-id="text-editor">
-        <state line="108" column="15" selection-start="3390" selection-end="3390" vertical-scroll-proportion="1.2724056">
-          <folding />
-        </state>
-      </provider>
-    </entry>
-    <entry file="file://$PROJECT_DIR$/pom.xml">
-      <provider selected="true" editor-type-id="text-editor">
-        <state line="8" column="0" selection-start="382" selection-end="382" vertical-scroll-proportion="0.10041841">
-          <folding />
-        </state>
-      </provider>
-    </entry>
-    <entry file="file://$PROJECT_DIR$/src/java/ognl/ASTAdd.java">
-      <provider selected="true" editor-type-id="text-editor">
-        <state line="277" column="52" selection-start="12131" selection-end="12131" vertical-scroll-proportion="0.67874795">
-          <folding />
-        </state>
-      </provider>
-    </entry>
     <entry file="file://$PROJECT_DIR$/src/java/ognl/OgnlOps.java">
       <provider selected="true" editor-type-id="text-editor">
         <state line="171" column="5" selection-start="6746" selection-end="6746" vertical-scroll-proportion="0.19686985">
         </state>
       </provider>
     </entry>
+    <entry file="file://$PROJECT_DIR$/src/java/ognl/ASTThisVarRef.java">
+      <provider selected="true" editor-type-id="text-editor">
+        <state line="40" column="0" selection-start="1945" selection-end="1945" vertical-scroll-proportion="0.13591433">
+          <folding />
+        </state>
+      </provider>
+    </entry>
+    <entry file="file://$PROJECT_DIR$/src/test/java/org/ognl/test/PropertyTest.java">
+      <provider selected="true" editor-type-id="text-editor">
+        <state line="125" column="0" selection-start="7962" selection-end="7962" vertical-scroll-proportion="0.33278418">
+          <folding />
+        </state>
+      </provider>
+    </entry>
+    <entry file="file://$PROJECT_DIR$/src/test/java/org/ognl/test/objects/Indexed.java">
+      <provider selected="true" editor-type-id="text-editor">
+        <state line="59" column="5" selection-start="2379" selection-end="2379" vertical-scroll-proportion="0.28336078">
+          <folding />
+        </state>
+      </provider>
+    </entry>
+    <entry file="file://$PROJECT_DIR$/src/test/java/org/ognl/test/objects/TestClass.java">
+      <provider selected="true" editor-type-id="text-editor">
+        <state line="8" column="0" selection-start="80" selection-end="80" vertical-scroll-proportion="0.098846786">
+          <folding />
+        </state>
+      </provider>
+    </entry>
+    <entry file="file://$PROJECT_DIR$/src/test/java/org/ognl/test/objects/Messages.java">
+      <provider selected="true" editor-type-id="text-editor">
+        <state line="33" column="23" selection-start="566" selection-end="566" vertical-scroll-proportion="0.407743">
+          <folding />
+        </state>
+      </provider>
+    </entry>
+    <entry file="file://$PROJECT_DIR$/src/test/java/org/ognl/test/IndexedPropertyTest.java">
+      <provider selected="true" editor-type-id="text-editor">
+        <state line="60" column="0" selection-start="3367" selection-end="3367" vertical-scroll-proportion="0.3583196">
+          <folding />
+        </state>
+      </provider>
+    </entry>
+    <entry file="file://$PROJECT_DIR$/src/test/java/org/ognl/test/ObjectIndexedPropertyTest.java">
+      <provider selected="true" editor-type-id="text-editor">
+        <state line="95" column="0" selection-start="4560" selection-end="4560" vertical-scroll-proportion="0.7784184">
+          <folding />
+        </state>
+      </provider>
+    </entry>
+    <entry file="file://$PROJECT_DIR$/src/test/java/ognl/TestOgnlRuntime.java">
+      <provider selected="true" editor-type-id="text-editor">
+        <state line="24" column="16" selection-start="648" selection-end="648" vertical-scroll-proportion="0.3360849">
+          <folding />
+        </state>
+      </provider>
+    </entry>
+    <entry file="file://$PROJECT_DIR$/src/java/ognl/ObjectPropertyAccessor.java">
+      <provider selected="true" editor-type-id="text-editor">
+        <state line="272" column="0" selection-start="9979" selection-end="9979" vertical-scroll-proportion="0.48105437">
+          <folding>
+            <element signature="imports" expanded="true" />
+          </folding>
+        </state>
+      </provider>
+    </entry>
+    <entry file="file://$PROJECT_DIR$/src/test/java/org/ognl/test/SelfReferenceReflectionTest.java">
+      <provider selected="true" editor-type-id="text-editor">
+        <state line="39" column="5" selection-start="858" selection-end="858" vertical-scroll-proportion="0.46869853">
+          <folding>
+            <element signature="imports" expanded="true" />
+          </folding>
+        </state>
+      </provider>
+    </entry>
+    <entry file="file://$PROJECT_DIR$/src/test/java/org/ognl/test/enhance/TestExpressionCompiler.java">
+      <provider selected="true" editor-type-id="text-editor">
+        <state line="135" column="46" selection-start="3866" selection-end="3866" vertical-scroll-proportion="0.184514">
+          <folding />
+        </state>
+      </provider>
+    </entry>
+    <entry file="file://$PROJECT_DIR$/src/java/ognl/enhance/ExpressionCompiler.java">
+      <provider selected="true" editor-type-id="text-editor">
+        <state line="476" column="45" selection-start="17188" selection-end="17188" vertical-scroll-proportion="0.23228996">
+          <folding />
+        </state>
+      </provider>
+    </entry>
   </component>
   <component name="testng.defaultConfiguration">
     <outputDirectory />

File src/java/ognl/ObjectPropertyAccessor.java

         } catch (Exception ex) {
             throw new OgnlException(name, ex);
         }
-        
+
         return result;
     }
 
         {
             throw new NoSuchPropertyException(target, name);
         }
-        
+
         return result;
     }
 
 
             // try last ditch effort of checking if they were trying to do reflection via a return method value
 
-            if (m == null && context.getCurrentObject() != null)
-                m = OgnlRuntime.getReadMethod(target.getClass(), context.getCurrentObject().toString().replaceAll("\"", ""));
+            //if (m == null && context.getCurrentObject() != null)
+            //  m = OgnlRuntime.getReadMethod(target.getClass(), context.getCurrentObject().toString().replaceAll("\"", ""));
 
             //System.out.println("tried to get read method from target: " + target.getClass() + " with methodName:" + methodName + " result: " + m);
             // try to get field if no method could be found
                     // ignore
                 }
 
-                return "";
+                throw new UnsupportedCompilationException("Unable to find method used for object access with index : " + methodName + " on target class: " + target.getClass());
             }
 
             context.setCurrentType(m.getReturnType());

File src/test/java/org/ognl/test/SelfReferenceReflectionTest.java

+package org.ognl.test;
+
+import junit.framework.TestCase;
+import ognl.Node;
+import ognl.Ognl;
+import ognl.OgnlContext;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Tests for bug OGNL-117.
+ */
+public class SelfReferenceReflectionTest 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");
+        OgnlContext context = (OgnlContext)Ognl.createDefaultContext(this);
+
+        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.clear();
+        Node expression2 = Ognl.compileExpression(context, this, "object[propertyKey]");
+        assertEquals("propertyValue", Ognl.getValue(expression2.getAccessor(), context, this)) ;
+
+        propertyKey = "integerProperty";
+
+        // Succeeds
+        assertEquals(1, Ognl.getValue(expression, context, this)) ;
+
+        context.clear();
+
+        // Fails with 2.7.1-20070723.185910-9
+        assertEquals(1, Ognl.getValue(expression, context, this)) ;
+    }
+}