1. opensymphony
  2. ognl

Commits

jkuh...@d4b077e3-5828-0410-b394-cb2b42183085  committed 57e8288

Fixes OGNL-93. ExpressionCompiler.castExpression wasn't checking for ASTStaticMethod expression types.

  • Participants
  • Parent commits 82632ab
  • Branches default

Comments (0)

Files changed (4)

File OGNL.iws

View file
  • Ignore whitespace
   </component>
   <component name="ChangeListManager">
     <list default="true" name="Default" comment="">
-      <change type="MODIFICATION" beforePath="$PROJECT_DIR$/src/test/java/ognl/TestOgnlRuntime.java" afterPath="$PROJECT_DIR$/src/test/java/ognl/TestOgnlRuntime.java" />
+      <change type="MODIFICATION" beforePath="$PROJECT_DIR$/src/test/java/org/ognl/test/MethodTest.java" afterPath="$PROJECT_DIR$/src/test/java/org/ognl/test/MethodTest.java" />
+      <change type="MODIFICATION" beforePath="$PROJECT_DIR$/src/java/ognl/enhance/ExpressionCompiler.java" afterPath="$PROJECT_DIR$/src/java/ognl/enhance/ExpressionCompiler.java" />
       <change type="MODIFICATION" beforePath="$PROJECT_DIR$/OGNL.iws" afterPath="$PROJECT_DIR$/OGNL.iws" />
-      <change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/src/java/ognl/ClassCacheInspector.java" />
-      <change type="MODIFICATION" beforePath="$PROJECT_DIR$/OGNL.ipr" afterPath="$PROJECT_DIR$/OGNL.ipr" />
-      <change type="MODIFICATION" beforePath="$PROJECT_DIR$/src/java/ognl/OgnlRuntime.java" afterPath="$PROJECT_DIR$/src/java/ognl/OgnlRuntime.java" />
+      <change type="MODIFICATION" beforePath="$PROJECT_DIR$/src/java/ognl/ASTMethod.java" afterPath="$PROJECT_DIR$/src/java/ognl/ASTMethod.java" />
     </list>
   </component>
   <component name="ChangesViewManager" flattened_view="true" show_ignored="false" />
     <option name="referencePos" value="0" />
     <option name="showLabels" value="true" />
   </component>
-  <component name="RunManager" selected="JUnit.PropertyTest">
-    <tempConfiguration default="false" name="PropertyTest" type="JUnit" factoryName="JUnit" enabled="false" merge="false">
+  <component name="RunManager" selected="JUnit.MethodTest">
+    <tempConfiguration default="false" name="MethodTest" type="JUnit" factoryName="JUnit" enabled="false" merge="false">
       <pattern value="org.ognl.test.*" />
       <module name="OGNL" />
       <option name="ALTERNATIVE_JRE_PATH_ENABLED" value="true" />
       <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.PropertyTest" />
+      <option name="MAIN_CLASS_NAME" value="org.ognl.test.MethodTest" />
       <option name="METHOD_NAME" value="" />
       <option name="TEST_OBJECT" value="class" />
       <option name="VM_PARAMETERS" value="" />
     <option name="PERFORM_EDIT_IN_BACKGROUND" value="true" />
     <option name="PERFORM_ADD_REMOVE_IN_BACKGROUND" value="true" />
     <option name="FORCE_NON_EMPTY_COMMENT" value="false" />
-    <option name="LAST_COMMIT_MESSAGE" value="Implemented ability to register a special class cache listener class to OgnlRuntime which makes it possible to prevent reflection caching of specific class types." />
+    <option name="LAST_COMMIT_MESSAGE" value="Fixes OGNL-93.  ExpressionCompiler.castExpression wasn't checking for ASTStaticMethod expression types." />
     <option name="OPTIMIZE_IMPORTS_BEFORE_PROJECT_COMMIT" value="true" />
     <option name="REFORMAT_BEFORE_PROJECT_COMMIT" value="false" />
     <option name="REFORMAT_BEFORE_FILE_COMMIT" value="false" />
     <option name="UPDATE_GROUP_BY_CHANGELIST" value="false" />
     <option name="SHOW_FILE_HISTORY_AS_TREE" value="false" />
     <option name="FILE_HISTORY_SPLITTER_PROPORTION" value="0.6" />
-    <MESSAGE value="Fixes OGNL-60 . OgnlOps wasn't converting simple object values to object arrays &amp;&amp; ASTMethod wasn't checking for void return types to parameter values." />
     <MESSAGE value="Fixes OGNL-62. OgnlRuntime.getReadMethod() wasn't checking for a valid return type in the second pass method matcher." />
     <MESSAGE value="Added some more tests but unable to re-produce bug." />
     <MESSAGE value="Fixes OGNL-61. ExpressionNode's and string concatenation wasn't working out so well without ()s." />
     <MESSAGE value="Fixes OGNL-89.  ASTCtor was calling ExpressionCompiler.getRootExpression() on child expression of ASTRootVarRef - which was also doing the same exact thing on itself." />
     <MESSAGE value="Fixes OGNL-91. God that bug sucked ass.... Finally did numeric coercion refactoring whether I liked it or not." />
     <MESSAGE value="Implemented ability to register a special class cache listener class to OgnlRuntime which makes it possible to prevent reflection caching of specific class types." />
+    <MESSAGE value="Fixes OGNL-93.  ExpressionCompiler.castExpression wasn't checking for ASTStaticMethod expression types." />
   </component>
   <component name="VssConfiguration">
     <option name="CLIENT_PATH" value="" />
     <option name="myLastEditedConfigurable" />
   </component>
   <component name="editorHistoryManager">
-    <entry file="file://$PROJECT_DIR$/src/java/ognl/OgnlOps.java">
-      <provider selected="true" editor-type-id="text-editor">
-        <state line="685" column="36" selection-start="25262" selection-end="25262" vertical-scroll-proportion="0.42068157">
-          <folding />
-        </state>
-      </provider>
-    </entry>
-    <entry file="file://$PROJECT_DIR$/src/java/ognl/ASTBitAnd.java">
-      <provider selected="true" editor-type-id="text-editor">
-        <state line="62" column="4" selection-start="2518" selection-end="2518" vertical-scroll-proportion="0.5816686">
-          <folding />
-        </state>
-      </provider>
-    </entry>
-    <entry file="file://$PROJECT_DIR$/src/java/ognl/ASTUnsignedShiftRight.java">
-      <provider selected="true" editor-type-id="text-editor">
-        <state line="65" column="0" selection-start="2616" selection-end="2616" vertical-scroll-proportion="0.3478261">
-          <folding />
-        </state>
-      </provider>
-    </entry>
     <entry file="file://$PROJECT_DIR$/src/test/java/org/ognl/test/ArithmeticAndLogicalOperatorsTest.java">
       <provider selected="true" editor-type-id="text-editor">
         <state line="112" column="37" selection-start="4863" selection-end="4863" vertical-scroll-proportion="0.4522613">
         </state>
       </provider>
     </entry>
-    <entry file="file://$PROJECT_DIR$/src/java/ognl/enhance/ExpressionCompiler.java">
-      <provider selected="true" editor-type-id="text-editor">
-        <state line="540" column="0" selection-start="19550" selection-end="19550" vertical-scroll-proportion="0.5025126">
-          <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="90" column="58" selection-start="5466" selection-end="5466" vertical-scroll-proportion="0.6345476">
         </state>
       </provider>
     </entry>
+    <entry file="file://$PROJECT_DIR$/src/test/java/org/ognl/test/ClassMethodTest.java">
+      <provider selected="true" editor-type-id="text-editor">
+        <state line="49" column="0" selection-start="2606" selection-end="2606" vertical-scroll-proportion="0.23869346">
+          <folding />
+        </state>
+      </provider>
+    </entry>
+    <entry file="file://$PROJECT_DIR$/src/java/ognl/ASTMethod.java">
+      <provider selected="true" editor-type-id="text-editor">
+        <state line="317" column="9" selection-start="12272" selection-end="12272" vertical-scroll-proportion="0.41833138">
+          <folding>
+            <element signature="imports" expanded="true" />
+          </folding>
+        </state>
+      </provider>
+    </entry>
+    <entry file="file://$PROJECT_DIR$/src/test/java/org/ognl/test/MethodTest.java">
+      <provider selected="true" editor-type-id="text-editor">
+        <state line="35" column="13" selection-start="1834" selection-end="1834" vertical-scroll-proportion="0.08813161">
+          <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="543" column="37" selection-start="19687" selection-end="19687" vertical-scroll-proportion="0.3517588">
+          <folding />
+        </state>
+      </provider>
+    </entry>
   </component>
   <component name="testng.defaultConfiguration">
     <outputDirectory />

File src/java/ognl/ASTMethod.java

View file
  • Ignore whitespace
 
     public String toGetSourceString(OgnlContext context, Object target)
     {
-       /* System.out.println("methodName is " + _methodName + " for target " + target + " target class: " + (target != null ? target.getClass() : null)
+      /*  System.out.println("methodName is " + _methodName + " for target " + target + " target class: " + (target != null ? target.getClass() : null)
                            + " current type: " + context.getCurrentType());*/
         if (target == null)
             throw new UnsupportedCompilationException("Target object is null.");
                 }
             }
             
-            Object contextObj = getValueBody(context, target);
-            
-            context.setCurrentObject(contextObj);
-
         } catch (Throwable t) {
             if (UnsupportedCompilationException.class.isInstance(t))
                 throw (UnsupportedCompilationException)t;
                 throw new RuntimeException(t);
         }
 
+        try {
+
+            Object contextObj = getValueBody(context, target);
+            context.setCurrentObject(contextObj);
+            
+        } catch (Throwable t) {
+            // ignore 
+        }
+
         result += ")" + post;
 
         if (m.getReturnType() == void.class) {
                     context.put(ExpressionCompiler.PRE_CAST, prevCast);
                 }
             }
-
-            Object contextObj = getValueBody(context, target);
-            
-            context.setCurrentObject(contextObj);
             
         } catch (Throwable t) {
             if (UnsupportedCompilationException.class.isInstance(t))
             else
                 throw new RuntimeException(t);
         }
-        
+
+        try {
+
+            Object contextObj = getValueBody(context, target);
+            context.setCurrentObject(contextObj);
+
+        } catch (Throwable t) {
+            // ignore
+        }
+
         context.setCurrentType(m.getReturnType());
         context.setCurrentAccessor(OgnlRuntime.getCompiler().getSuperOrInterfaceClass(m, m.getDeclaringClass()));
         

File src/java/ognl/enhance/ExpressionCompiler.java

View file
  • Ignore whitespace
     {
         if (ASTChain.class.isInstance(expression))
         {
-
+            
             if (ASTConst.class.isInstance(expression.jjtGetChild(0))
                 || ASTStaticMethod.class.isInstance(expression.jjtGetChild(0))
                 || ASTStaticField.class.isInstance(expression.jjtGetChild(0))
     public String castExpression(OgnlContext context, Node expression, String body)
     {
         // ok - so this looks really f-ed up ...and it is ..eh if you can do it better I'm all for it :)
+
         
+
         if (context.getCurrentAccessor() == null
             || context.getPreviousType() == null
             || context.getCurrentAccessor().isAssignableFrom(context.getPreviousType())
             || context.getCurrentAccessor() == Class.class
             || (context.get(ExpressionCompiler.PRE_CAST) != null && ((String) context.get(ExpressionCompiler.PRE_CAST)).startsWith("new"))
             || ASTStaticField.class.isInstance(expression)
+            || ASTStaticMethod.class.isInstance(expression)
             || (OrderedReturn.class.isInstance(expression) && ((OrderedReturn) expression).getLastExpression() != null))
             return body;
 
 
-        /* System.out.println("castExpression() with expression " + expression + " expr class: " + expression.getClass() + " currentType is: " + context.getCurrentType()
+/*         System.out.println("castExpression() with expression " + expression + " expr class: " + expression.getClass() + " currentType is: " + context.getCurrentType()
                       + " previousType: " + context.getPreviousType()
                       + "\n current Accessor: " + context.getCurrentAccessor()
                       + " previous Accessor: " + context.getPreviousAccessor()
-                      + " current object " + context.getCurrentObject());
-        */
+                      + " current object " + context.getCurrentObject());*/
 
         ExpressionCompiler.addCastString(context, "((" + ExpressionCompiler.getCastString(context.getCurrentAccessor()) + ")");
 

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

View file
  • Ignore whitespace
             { "getBooleanValue() ? \"here\" : \"\"", ""},
             { "getValueIsTrue(!false) ? \"\" : \"here\" ", ""},
             { "messages.format('ShowAllCount', one)", "foo"},
-            { "getTestValue(@org.ognl.test.objects.SimpleEnum@ONE.value)", new Integer(2)}
+            { "getTestValue(@org.ognl.test.objects.SimpleEnum@ONE.value)", new Integer(2)},
+            { "@org.ognl.test.MethodTest@getA().isProperty()", Boolean.FALSE}
     };
 
+    public static class A
+    {
+        public boolean isProperty()
+        {
+            return false;
+        }
+    }
+
+    public static A getA()
+    {
+        return new A();
+    }
+
     /*
     * =================================================================== Public static methods
     * ===================================================================