Commits

jkuh...@d4b077e3-5828-0410-b394-cb2b42183085  committed 7575d53

Fixes OGNL-74. Used a 1.5 only jre feature of Integer.valueOf(int)

  • Participants
  • Parent commits cfa2c69

Comments (0)

Files changed (7)

   </component>
   <component name="ChangeListManager">
     <list default="true" name="Default" comment="">
-      <change type="MODIFICATION" beforePath="$PROJECT_DIR$/src/test/java/org/ognl/test/objects/Entry.java" afterPath="$PROJECT_DIR$/src/test/java/org/ognl/test/objects/Entry.java" />
-      <change type="MODIFICATION" beforePath="$PROJECT_DIR$/src/java/ognl/ASTCtor.java" afterPath="$PROJECT_DIR$/src/java/ognl/ASTCtor.java" />
+      <change type="MODIFICATION" beforePath="$PROJECT_DIR$/src/java/ognl/ListPropertyAccessor.java" afterPath="$PROJECT_DIR$/src/java/ognl/ListPropertyAccessor.java" />
+      <change type="MODIFICATION" beforePath="$PROJECT_DIR$/src/java/ognl/ArrayPropertyAccessor.java" afterPath="$PROJECT_DIR$/src/java/ognl/ArrayPropertyAccessor.java" />
+      <change type="MODIFICATION" beforePath="$PROJECT_DIR$/src/test/java/org/ognl/test/ASTPropertyTest.java" afterPath="$PROJECT_DIR$/src/test/java/org/ognl/test/ASTPropertyTest.java" />
+      <change type="MODIFICATION" beforePath="$PROJECT_DIR$/pom.xml" afterPath="$PROJECT_DIR$/pom.xml" />
       <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$/src/java/ognl/OgnlOps.java" afterPath="$PROJECT_DIR$/src/java/ognl/OgnlOps.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/ArrayCreationTest.java" afterPath="$PROJECT_DIR$/src/test/java/org/ognl/test/ArrayCreationTest.java" />
     </list>
   </component>
   <component name="ChangesViewManager" flattened_view="true" show_ignored="false" />
     <option name="showLabels" value="true" />
   </component>
   <component name="RestoreUpdateTree" />
-  <component name="RunManager" selected="JUnit.ArrayCreationTest">
-    <tempConfiguration default="false" name="ArrayCreationTest" type="JUnit" factoryName="JUnit" enabled="false" merge="false">
+  <component name="RunManager" selected="JUnit.ASTPropertyTest">
+    <tempConfiguration default="false" name="ASTPropertyTest" 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.ArrayCreationTest" />
+      <option name="MAIN_CLASS_NAME" value="org.ognl.test.ASTPropertyTest" />
       <option name="METHOD_NAME" value="" />
       <option name="TEST_OBJECT" value="class" />
       <option name="VM_PARAMETERS" value="" />
       <window_info id="Changes" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.23937908" order="8" />
       <window_info id="Palette" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" order="3" />
       <window_info id="Ant Build" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.25" order="1" />
-      <window_info id="Find" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.32761437" order="1" />
+      <window_info id="Find" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.32651392" order="1" />
       <window_info id="Debug" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.2755187" order="3" />
       <window_info id="Version Control" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.2381342" order="8" />
       <window_info id="Messages" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.26595744" order="8" />
     <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="Fixes OGNL-72. ASTCtor was setting the generic type instead of the actual type... This was breaking things when the type being constructed was an array." />
+    <option name="LAST_COMMIT_MESSAGE" value="Fixes OGNL-74. Used a 1.5 only jre feature of Integer.valueOf(int)" />
     <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_PACKAGES" value="false" />
     <option name="SHOW_FILE_HISTORY_AS_TREE" value="false" />
     <option name="FILE_HISTORY_SPLITTER_PROPORTION" value="0.6" />
-    <MESSAGE value="Fixes regression of string concatenations in OGNL-48." />
     <MESSAGE value="Fixes OGNL-46. ExpressionCompiler.getRootExpression() was incorrectly casting directly to the root type instead of checking the context accessor type first. (to be friendly with object inheritance)" />
     <MESSAGE value="Re-factored OgnlContext type / accessor logic to use backing List objects so that the full type chain can be evaluated after the fact." />
     <MESSAGE value="Added new getRootExpressionClass() to compiler interface so that other compiler impls can handle special corner cases (like operating on previously javassist'ed classes)" />
     <MESSAGE value="Fixes OGNL-47 and possibly all enum related bugs. We'll see." />
     <MESSAGE value="Fixes OGNL-73. When evaluating child source strings via the OgnlRuntime.getChildSource() method standard runtime exceptions weren't being properly handled..The more correct way to handle those is to throw an UnsupportedCompilationException so that they can be re-evaluated later and possibly compiled natively when more objects in the expression are resolvable." />
     <MESSAGE value="Fixes OGNL-72. ASTCtor was setting the generic type instead of the actual type... This was breaking things when the type being constructed was an array." />
+    <MESSAGE value="Fixes OGNL-74. Used a 1.5 only jre feature of Integer.valueOf(int)" />
   </component>
   <component name="XPathView.XPathProjectComponent">
     <history />
     <option name="myLastEditedConfigurable" />
   </component>
   <component name="editorHistoryManager">
-    <entry file="file://$PROJECT_DIR$/src/java/ognl/OgnlRuntime.java">
-      <provider selected="true" editor-type-id="text-editor">
-        <state line="2191" column="9" selection-start="84180" selection-end="84180" vertical-scroll-proportion="0.55919397">
-          <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="94" column="71" selection-start="5805" selection-end="5805" vertical-scroll-proportion="0.22670025">
-          <folding>
-            <element signature="imports" expanded="true" />
-          </folding>
-        </state>
-      </provider>
-    </entry>
-    <entry file="file://$PROJECT_DIR$/src/java/ognl/ASTProperty.java">
-      <provider selected="true" editor-type-id="text-editor">
-        <state line="529" column="0" selection-start="23335" selection-end="23335" vertical-scroll-proportion="0.5214106">
-          <folding />
-        </state>
-      </provider>
-    </entry>
-    <entry file="file://$PROJECT_DIR$/src/test/java/org/ognl/test/OperatorTest.java">
-      <provider selected="true" editor-type-id="text-editor">
-        <state line="52" column="0" selection-start="2708" selection-end="2708" vertical-scroll-proportion="0.28967255">
-          <folding />
-        </state>
-      </provider>
-    </entry>
-    <entry file="file://$PROJECT_DIR$/src/test/java/org/ognl/test/CompilingPropertyAccessor.java">
-      <provider selected="true" editor-type-id="text-editor">
-        <state line="68" column="0" selection-start="2818" selection-end="2818" vertical-scroll-proportion="0.28967255">
-          <folding />
-        </state>
-      </provider>
-    </entry>
-    <entry file="file://$PROJECT_DIR$/src/test/java/org/ognl/test/CollectionDirectPropertyTest.java">
-      <provider selected="true" editor-type-id="text-editor">
-        <state line="60" column="6" selection-start="3317" selection-end="3317" vertical-scroll-proportion="0.35264483">
-          <folding />
-        </state>
-      </provider>
-    </entry>
-    <entry file="file://$PROJECT_DIR$/src/test/java/org/ognl/test/objects/Root.java">
-      <provider selected="true" editor-type-id="text-editor">
-        <state line="234" column="0" selection-start="7303" selection-end="7303" vertical-scroll-proportion="0.3652393">
-          <folding />
-        </state>
-      </provider>
-    </entry>
-    <entry file="file://$PROJECT_DIR$/src/test/java/org/ognl/test/objects/Inherited.java">
-      <provider selected="true" editor-type-id="text-editor">
-        <state line="9" column="0" selection-start="101" selection-end="101" vertical-scroll-proportion="0.11335012">
-          <folding />
-        </state>
-      </provider>
-    </entry>
     <entry file="file://$PROJECT_DIR$/src/test/java/org/ognl/test/objects/Simple.java">
       <provider selected="true" editor-type-id="text-editor">
         <state line="63" column="5" selection-start="2560" selection-end="2560" vertical-scroll-proportion="0.3652393">
         </state>
       </provider>
     </entry>
-    <entry file="file://$PROJECT_DIR$/src/java/ognl/enhance/ExpressionCompiler.java">
+    <entry file="file://$PROJECT_DIR$/src/java/ognl/ASTCtor.java">
       <provider selected="true" editor-type-id="text-editor">
-        <state line="535" column="12" selection-start="19027" selection-end="19027" vertical-scroll-proportion="0.012594459">
+        <state line="239" column="53" selection-start="8973" selection-end="8973" vertical-scroll-proportion="0.47858942">
           <folding />
         </state>
       </provider>
     </entry>
-    <entry file="file://$PROJECT_DIR$/src/java/ognl/ASTCtor.java">
+    <entry file="file://$PROJECT_DIR$/pom.xml">
       <provider selected="true" editor-type-id="text-editor">
-        <state line="239" column="53" selection-start="8973" selection-end="8973" vertical-scroll-proportion="0.47858942">
+        <state line="86" column="31" selection-start="2969" selection-end="2969" vertical-scroll-proportion="0.5408163">
+          <folding />
+        </state>
+      </provider>
+    </entry>
+    <entry file="file://$PROJECT_DIR$/src/java/ognl/Ognl.java">
+      <provider selected="true" editor-type-id="text-editor">
+        <state line="89" column="22" selection-start="4327" selection-end="4327" vertical-scroll-proportion="0.33333334">
+          <folding />
+        </state>
+      </provider>
+    </entry>
+    <entry file="jar:///usr/local/jdk1.5.0_11/src.zip!/java/math/BigInteger.java">
+      <provider selected="true" editor-type-id="text-editor">
+        <state line="927" column="29" selection-start="33828" selection-end="33828" vertical-scroll-proportion="0.33333334">
+          <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="497" column="0" selection-start="17584" selection-end="17584" vertical-scroll-proportion="0.35768262">
+          <folding />
+        </state>
+      </provider>
+    </entry>
+    <entry file="file://$PROJECT_DIR$/src/java/ognl/ArrayPropertyAccessor.java">
+      <provider selected="true" editor-type-id="text-editor">
+        <state line="221" column="16" selection-start="9144" selection-end="9144" vertical-scroll-proportion="0.77070063">
+          <folding />
+        </state>
+      </provider>
+    </entry>
+    <entry file="file://$PROJECT_DIR$/src/java/ognl/ListPropertyAccessor.java">
+      <provider selected="true" editor-type-id="text-editor">
+        <state line="265" column="77" selection-start="10490" selection-end="10490" vertical-scroll-proportion="0.7324841">
+          <folding />
+        </state>
+      </provider>
+    </entry>
+    <entry file="file://$PROJECT_DIR$/src/test/java/org/ognl/test/ASTPropertyTest.java">
+      <provider selected="true" editor-type-id="text-editor">
+        <state line="199" column="116" selection-start="6876" selection-end="6876" vertical-scroll-proportion="0.59697735">
+          <folding />
+        </state>
+      </provider>
+    </entry>
+    <entry file="file://$PROJECT_DIR$/src/java/ognl/OgnlOps.java">
+      <provider selected="true" editor-type-id="text-editor">
+        <state line="627" column="11" selection-start="23245" selection-end="23245" vertical-scroll-proportion="0.26028547">
+          <folding />
+        </state>
+      </provider>
+    </entry>
+    <entry file="file://$PROJECT_DIR$/src/java/ognl/OgnlRuntime.java">
+      <provider selected="true" editor-type-id="text-editor">
+        <state line="52" column="13" selection-start="2341" selection-end="2341" vertical-scroll-proportion="0.17632242">
           <folding />
         </state>
       </provider>
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-source-plugin</artifactId>
+                <configuration>
+                    <archive>
+                        <compress>true</compress>
+                        <index>true</index>
+                    </archive>
+                </configuration>
                 <executions>
                     <execution>
                         <goals>
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-javadoc-plugin</artifactId>
+                <configuration>
+                    <archive>
+                        <compress>true</compress>
+                        <index>true</index>
+                    </archive>
+                </configuration>
                 <executions>
                     <execution>
                         <goals>
                 <version>2.2-SNAPSHOT</version>
             </plugin>
         </plugins>
-
-        <!--
-        <extensions>
-            <extension>
-                <groupId>org.apache.maven.wagon</groupId>
-                <artifactId>wagon-ftp</artifactId>
-                <version>1.0-beta-1</version>
-            </extension>
-        </extensions>
-        -->
     </build>
     
     <distributionManagement>

File src/java/ognl/ArrayPropertyAccessor.java

 
             String toString = String.class.isInstance(index) && context.getCurrentType() != Object.class ? "" : ".toString()";
 
-            indexStr = "java.lang.Integer.valueOf(" + indexStr + toString + ").intValue()";
+            indexStr = "ognl.OgnlOps#getIntValue(" + indexStr + toString + ")";
         }
 
         context.setCurrentAccessor(target.getClass());
 
             String toString = String.class.isInstance(index) && context.getCurrentType() != Object.class ? "" : ".toString()";
 
-            indexStr = "java.lang.Integer.valueOf(" + indexStr + toString + ").intValue()";
+            indexStr = "ognl.OgnlOps#getIntValue(" + indexStr + toString + ")";
         }
 
         Class type = target.getClass().isArray() ? target.getClass().getComponentType() : target.getClass();

File src/java/ognl/ListPropertyAccessor.java

 
             String toString = String.class.isInstance(index) && context.getCurrentType() != Object.class ? "" : ".toString()";
 
-            indexStr = "java.lang.Integer.valueOf(" + indexStr + toString + ").intValue()";
+            indexStr = "ognl.OgnlOps#getIntValue(" + indexStr + toString + ")";
         }
         
         context.setCurrentType(Object.class);
 
             String toString = String.class.isInstance(index) && context.getCurrentType() != Object.class ? "" : ".toString()";
 
-            indexStr = "java.lang.Integer.valueOf(" + indexStr + toString + ").intValue()";
+            indexStr = "ognl.OgnlOps#getIntValue(" + indexStr + toString + ")";
         }
         
         context.setCurrentType(Object.class);

File src/java/ognl/OgnlOps.java

 
         return result;
     }
-    
+
+    /**
+     * Converts the specified value to a primitive integer value.
+     *
+     * <ul>
+     *  <li>Null values will cause a -1 to be returned.</li>
+     *  <li>{@link Number} instances have their intValue() methods invoked.</li>
+     *  <li>All other types result in calling Integer.parseInt(value.toString());</li>
+     * </ul>
+     *
+     * @param value
+     *          The object to get the value of.
+     * @return A valid integer.
+     */
+    public static int getIntValue(Object value)
+    {
+        try
+        {
+            if (value == null)
+                return -1;
+
+            if (Number.class.isInstance(value)) {
+
+                return ((Number)value).intValue();
+            }
+
+            String str = String.class.isInstance(value) ? (String)value : value.toString();
+            
+            return Integer.parseInt(str);
+        }
+        catch (Throwable t)
+        {
+            throw new RuntimeException("Error converting " + value + " to integer:", t);
+        }
+    }
+
     /**
      * Returns the constant from the NumericTypes interface that best expresses the type of a
      * numeric operation on the two given objects.

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

             context.put(LOCAL_REFERENCE_MAP, new LinkedHashMap());
         }
 
-        counter = Integer.valueOf(counter.intValue() + 1);
+        counter = new Integer(counter.intValue() + 1);
         context.put(LOCAL_REFERENCE_COUNTER, counter);
 
         Map referenceMap = (Map) context.get(LOCAL_REFERENCE_MAP);

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

 
         // test with only getIndex
 
-        assertEquals(".get(java.lang.Integer.valueOf(((org.ognl.test.objects.Root)$2)..getGenericIndex().toString()).intValue())", p.toGetSourceString(context, root.getList()));
+        assertEquals(".get(ognl.OgnlOps#getIntValue(((org.ognl.test.objects.Root)$2)..getGenericIndex().toString()))", p.toGetSourceString(context, root.getList()));
         assertEquals(root.getArray(), context.getCurrentObject());
         assertEquals(root.getArray().getClass().getComponentType(), context.getCurrentType());
     }