Commits

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

Fixes OGNL-85. Error with type conversion in constructor calls. Finally refactored ASTCtor to really dig through the available constructors and more thoroughly convert parameter types when possible.

  • Participants
  • Parent commits c13450e

Comments (0)

Files changed (5)

   </component>
   <component name="ChangeListManager">
     <list default="true" name="Default" comment="">
-      <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/test/java/org/ognl/test/objects/Root.java" afterPath="$PROJECT_DIR$/src/test/java/org/ognl/test/objects/Root.java" />
-      <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" />
-      <change type="MODIFICATION" beforePath="$PROJECT_DIR$/src/test/java/org/ognl/test/PropertyTest.java" afterPath="$PROJECT_DIR$/src/test/java/org/ognl/test/PropertyTest.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/ASTProperty.java" afterPath="$PROJECT_DIR$/src/java/ognl/ASTProperty.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/test/java/org/ognl/test/StaticsAndConstructorsTest.java" afterPath="$PROJECT_DIR$/src/test/java/org/ognl/test/StaticsAndConstructorsTest.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/test/java/org/ognl/test/objects/BaseIndexed.java" />
-      <change type="MODIFICATION" beforePath="$PROJECT_DIR$/src/java/ognl/ASTChain.java" afterPath="$PROJECT_DIR$/src/java/ognl/ASTChain.java" />
-      <change type="MODIFICATION" beforePath="$PROJECT_DIR$/src/java/ognl/ASTMethod.java" afterPath="$PROJECT_DIR$/src/java/ognl/ASTMethod.java" />
+      <change type="MODIFICATION" beforePath="$PROJECT_DIR$/src/java/ognl/OgnlRuntime.java" afterPath="$PROJECT_DIR$/src/java/ognl/OgnlRuntime.java" />
     </list>
   </component>
   <component name="ChangesViewManager" flattened_view="true" show_ignored="false" />
     <subPane>
       <PATH>
         <PATH_ELEMENT>
-          <option name="myItemId" value="com.intellij.openapi.project.impl.ProjectImpl@178ff42" />
+          <option name="myItemId" value="com.intellij.openapi.project.impl.ProjectImpl@186780d" />
           <option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.ProjectViewProjectNode" />
         </PATH_ELEMENT>
         <PATH_ELEMENT>
       </PATH>
       <PATH>
         <PATH_ELEMENT>
-          <option name="myItemId" value="com.intellij.openapi.project.impl.ProjectImpl@178ff42" />
+          <option name="myItemId" value="com.intellij.openapi.project.impl.ProjectImpl@186780d" />
           <option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.ProjectViewProjectNode" />
         </PATH_ELEMENT>
         <PATH_ELEMENT>
       <showLibraryContents />
       <hideEmptyPackages />
       <abbreviatePackageNames />
-      <showStructure ProjectPane="false" Scope="false" PackagesPane="false" Favorites="false" />
+      <showStructure PackagesPane="false" Scope="false" Favorites="false" ProjectPane="false" />
       <autoscrollToSource />
       <autoscrollFromSource />
       <sortByType />
     <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.StaticsAndConstructorsTest">
+    <tempConfiguration default="false" name="StaticsAndConstructorsTest" 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.IndexedPropertyTest" />
+      <option name="MAIN_CLASS_NAME" value="org.ognl.test.StaticsAndConstructorsTest" />
       <option name="METHOD_NAME" value="" />
       <option name="TEST_OBJECT" value="class" />
       <option name="VM_PARAMETERS" value="" />
         <option name="Make" value="true" />
       </method>
     </tempConfiguration>
+    <configuration default="true" type="Applet" factoryName="Applet">
+      <module name="" />
+      <option name="MAIN_CLASS_NAME" />
+      <option name="HTML_FILE_NAME" />
+      <option name="HTML_USED" value="false" />
+      <option name="WIDTH" value="400" />
+      <option name="HEIGHT" value="300" />
+      <option name="POLICY_FILE" value="$APPLICATION_HOME_DIR$/bin/appletviewer.policy" />
+      <option name="VM_PARAMETERS" />
+      <option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
+      <option name="ALTERNATIVE_JRE_PATH" />
+    </configuration>
+    <configuration default="true" type="Remote" factoryName="Remote">
+      <option name="USE_SOCKET_TRANSPORT" value="true" />
+      <option name="SERVER_MODE" value="false" />
+      <option name="SHMEM_ADDRESS" value="javadebug" />
+      <option name="HOST" value="localhost" />
+      <option name="PORT" value="5005" />
+    </configuration>
+    <configuration default="true" type="TestNG" factoryName="TestNG" enabled="false" merge="false">
+      <module name="" />
+      <option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
+      <option name="ALTERNATIVE_JRE_PATH" value="" />
+      <option name="SUITE_NAME" value="" />
+      <option name="PACKAGE_NAME" />
+      <option name="MAIN_CLASS_NAME" value="" />
+      <option name="METHOD_NAME" />
+      <option name="GROUP_NAME" value="" />
+      <option name="TEST_OBJECT" value="CLASS" />
+      <option name="VM_PARAMETERS" value="" />
+      <option name="PARAMETERS" value="" />
+      <option name="WORKING_DIRECTORY" value="file://$PROJECT_DIR$/build" />
+      <option name="OUTPUT_DIRECTORY" value="" />
+      <option name="ADDITIONAL_CLASS_PATH" />
+      <option name="TEST_SEARCH_SCOPE">
+        <value defaultName="singleModule" />
+      </option>
+      <option name="PROPERTIES_FILE" value="" />
+      <properties />
+      <method>
+        <option name="Make" value="true" />
+      </method>
+    </configuration>
     <configuration default="true" type="JUnit" factoryName="JUnit" enabled="false" merge="false">
       <module name="" />
       <option name="ALTERNATIVE_JRE_PATH_ENABLED" value="true" />
       <option name="ENV_VARIABLES" />
       <module name="" />
     </configuration>
-    <configuration default="true" type="Applet" factoryName="Applet">
-      <module name="" />
-      <option name="MAIN_CLASS_NAME" />
-      <option name="HTML_FILE_NAME" />
-      <option name="HTML_USED" value="false" />
-      <option name="WIDTH" value="400" />
-      <option name="HEIGHT" value="300" />
-      <option name="POLICY_FILE" value="$APPLICATION_HOME_DIR$/bin/appletviewer.policy" />
-      <option name="VM_PARAMETERS" />
-      <option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
-      <option name="ALTERNATIVE_JRE_PATH" />
-    </configuration>
-    <configuration default="true" type="TestNG" factoryName="TestNG" enabled="false" merge="false">
-      <module name="" />
-      <option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
-      <option name="ALTERNATIVE_JRE_PATH" value="" />
-      <option name="SUITE_NAME" value="" />
-      <option name="PACKAGE_NAME" />
-      <option name="MAIN_CLASS_NAME" value="" />
-      <option name="METHOD_NAME" />
-      <option name="GROUP_NAME" value="" />
-      <option name="TEST_OBJECT" value="CLASS" />
-      <option name="VM_PARAMETERS" value="" />
-      <option name="PARAMETERS" value="" />
-      <option name="WORKING_DIRECTORY" value="file://$PROJECT_DIR$/build" />
-      <option name="OUTPUT_DIRECTORY" value="" />
-      <option name="ADDITIONAL_CLASS_PATH" />
-      <option name="TEST_SEARCH_SCOPE">
-        <value defaultName="singleModule" />
-      </option>
-      <option name="PROPERTIES_FILE" value="" />
-      <properties />
-      <method>
-        <option name="Make" value="true" />
-      </method>
-    </configuration>
-    <configuration default="true" type="Remote" factoryName="Remote">
-      <option name="USE_SOCKET_TRANSPORT" value="true" />
-      <option name="SERVER_MODE" value="false" />
-      <option name="SHMEM_ADDRESS" value="javadebug" />
-      <option name="HOST" value="localhost" />
-      <option name="PORT" value="5005" />
-    </configuration>
     <configuration default="true" type="#com.intellij.j2ee.web.tomcat.TomcatRunConfigurationFactory" factoryName="Local">
       <option name="WORKING_DIRECTORY" />
       <option name="HOST" value="localhost" />
       <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.26530612" order="8" />
       <window_info id="TODO" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" order="7" />
-      <window_info id="Structure" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.24975657" order="1" />
+      <window_info id="Structure" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.24943718" order="1" />
       <window_info id="Commander" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.4" order="0" />
       <window_info id="Module Dependencies" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" order="3" />
       <window_info id="Dependency Viewer" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" order="8" />
-      <window_info id="Project" active="true" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" weight="0.2683476" order="0" />
+      <window_info id="Project" active="true" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" weight="0.25529042" order="0" />
       <window_info id="Hierarchy" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.25" order="2" />
       <window_info id="Inspection" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.3488372" order="6" />
       <window_info id="Duplicates" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" 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-84, OGNL-83.  Precasting statements were being stolen by ASTMethod for inner children incorrectly.  ASTProperty also wasn't setting the correct current type on previously indexed methods. &#10;&#10;Also reverted surefire version since someone there seems to have broken the current version." />
+    <option name="LAST_COMMIT_MESSAGE" value="Fixes OGNL-85.  Error with type conversion in constructor calls.  Finally refactored ASTCtor to really dig through the available constructors and more thoroughly convert parameter types when possible." />
     <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="-) Fix for OGNL-52. Added a synchronized() block around the method object being invoked to prevent failures with the accessible flag being turned on/off temporarily. &#10;&#10;-) Added new unit test but failed to verify OGNL-51." />
     <MESSAGE value="Fixes OGNL-54. OgnlRuntime method finders and getChildSource weren't properly handling properties that should only be referencing root expressions (if any)..Such as method parameters / etc..Added logic to correctly set the context type/object state up for each of these." />
     <MESSAGE value="Fixes OGNL-55.&#10;&#10;ExpressionCompiler.shouldCast(Node) was returning true for ASTConst ...Obviousoly not correct." />
     <MESSAGE value="Fixed small error with ASTTest expressions containing sub-expressions without any paranthetical boundaries." />
     <MESSAGE value="Fixes OGNL-77. ASTAdd wasn't setting the context type before returning." />
     <MESSAGE value="Fixes TAPESTRY-1419. Needed to add () around widening expressions in ASTList." />
     <MESSAGE value="Fixes OGNL-84, OGNL-83.  Precasting statements were being stolen by ASTMethod for inner children incorrectly.  ASTProperty also wasn't setting the correct current type on previously indexed methods. &#10;&#10;Also reverted surefire version since someone there seems to have broken the current version." />
+    <MESSAGE value="Fixes OGNL-85.  Error with type conversion in constructor calls.  Finally refactored ASTCtor to really dig through the available constructors and more thoroughly convert parameter types when possible." />
   </component>
   <component name="XPathView.XPathProjectComponent">
     <history />
     <option name="myLastEditedConfigurable" />
   </component>
   <component name="editorHistoryManager">
-    <entry file="file://$PROJECT_DIR$/src/java/ognl/ObjectPropertyAccessor.java">
-      <provider selected="true" editor-type-id="text-editor">
-        <state line="222" column="54" selection-start="8064" selection-end="8064" vertical-scroll-proportion="0.42629817">
-          <folding />
-        </state>
-      </provider>
-    </entry>
-    <entry file="jar:///usr/local/jdk1.5.0_11/src.zip!/java/util/List.java">
-      <provider selected="true" editor-type-id="text-editor">
-        <state line="89" column="17" selection-start="4130" selection-end="4130" vertical-scroll-proportion="0.33333334">
-          <folding />
-        </state>
-      </provider>
-    </entry>
-    <entry file="file://$PROJECT_DIR$/src/java/ognl/ListPropertyAccessor.java">
-      <provider selected="true" editor-type-id="text-editor">
-        <state line="218" column="8" selection-start="8554" selection-end="8554" vertical-scroll-proportion="0.6482412">
-          <folding />
-        </state>
-      </provider>
-    </entry>
-    <entry file="file://$PROJECT_DIR$/src/java/ognl/ASTProperty.java">
-      <provider selected="true" editor-type-id="text-editor">
-        <state line="185" column="0" selection-start="6936" selection-end="6936" vertical-scroll-proportion="0.73325497">
-          <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="188" column="38" selection-start="6335" selection-end="6335" vertical-scroll-proportion="0.68592966">
         </state>
       </provider>
     </entry>
-    <entry file="file://$PROJECT_DIR$/src/java/ognl/ASTMethod.java">
-      <provider selected="true" editor-type-id="text-editor">
-        <state line="219" column="0" selection-start="7760" selection-end="7760" vertical-scroll-proportion="0.5477387">
-          <folding />
-        </state>
-      </provider>
-    </entry>
     <entry file="file://$PROJECT_DIR$/src/test/java/org/ognl/test/objects/Bean2.java">
       <provider selected="true" editor-type-id="text-editor">
         <state line="47" column="0" selection-start="2020" selection-end="2020" vertical-scroll-proportion="0.22613065">
         </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="99" column="31" selection-start="4513" selection-end="4513" vertical-scroll-proportion="0.28894472">
-          <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="3289" selection-end="3289" vertical-scroll-proportion="0.36432162">
         </state>
       </provider>
     </entry>
+    <entry file="file://$PROJECT_DIR$/src/java/ognl/ASTMethod.java">
+      <provider selected="true" editor-type-id="text-editor">
+        <state line="214" column="0" selection-start="7523" selection-end="7523" vertical-scroll-proportion="0.44065806">
+          <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="231" column="0" selection-start="7348" selection-end="7348" vertical-scroll-proportion="0.3149236">
+          <folding />
+        </state>
+      </provider>
+    </entry>
+    <entry file="file://$PROJECT_DIR$/src/java/ognl/ObjectArrayPool.java">
+      <provider selected="true" editor-type-id="text-editor">
+        <state line="156" column="5" selection-start="4932" selection-end="4932" vertical-scroll-proportion="0.43830788">
+          <folding />
+        </state>
+      </provider>
+    </entry>
+    <entry file="file://$PROJECT_DIR$/src/java/ognl/OgnlRuntime.java">
+      <provider selected="true" editor-type-id="text-editor">
+        <state line="374" column="67" selection-start="15549" selection-end="15549" vertical-scroll-proportion="0.4559342">
+          <folding />
+        </state>
+      </provider>
+    </entry>
+    <entry file="file://$PROJECT_DIR$/src/test/java/org/ognl/test/StaticsAndConstructorsTest.java">
+      <provider selected="true" editor-type-id="text-editor">
+        <state line="106" column="67" selection-start="3995" selection-end="3995" vertical-scroll-proportion="0.2713568">
+          <folding>
+            <element signature="imports" expanded="true" />
+          </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="54" selection-start="19331" selection-end="19331" vertical-scroll-proportion="0.23869346">
+        <state line="473" column="0" selection-start="16850" selection-end="16850" vertical-scroll-proportion="0.24958123">
+          <folding />
+        </state>
+      </provider>
+    </entry>
+    <entry file="file://$PROJECT_DIR$/src/java/ognl/ASTCtor.java">
+      <provider selected="true" editor-type-id="text-editor">
+        <state line="268" column="25" selection-start="10280" selection-end="10280" vertical-scroll-proportion="0.22110553">
           <folding />
         </state>
       </provider>

File src/java/ognl/ASTCtor.java

 import ognl.enhance.UnsupportedCompilationException;
 
 import java.lang.reflect.Array;
+import java.lang.reflect.Constructor;
 import java.util.List;
 
 /**
 
                 if ((_children != null) && (_children.length > 0)) {
 
+                    Object[] values = new Object[_children.length];
+                    String[] expressions = new String[_children.length];
+                    Class[] types = new Class[_children.length];
+
+                    // first populate arrays with child values
                     
                     for(int i = 0; i < _children.length; i++) {
-                        if (i > 0) {
-                            result = result + ", ";
-                        }
                         
                         Object objValue = _children[i].getValue(context, context.getRoot());
                         String value = _children[i].toGetSourceString(context, target);
-                        
+
                         value = ExpressionCompiler.getRootExpression(_children[i], target, context) + value;
 
-                        // System.out.println("astctor child class: " + _children[i].getClass() + " value: " + value);
-
                         String cast = "";
                         if (ExpressionCompiler.shouldCast(_children[i])) {
 
                         if (!ASTConst.class.isInstance(_children[i]))
                             value = cast + value;
 
-                        if (context.getCurrentType().isPrimitive()) {
-                            
-                            String literal = OgnlRuntime.getNumericLiteral(context.getCurrentType());
+                        values[i] = objValue;
+                        expressions[i] = value;
+                        types[i] = context.getCurrentType();
+                    }
+
+                    // now try and find a matching constructor
+                    
+                    Constructor[] cons = clazz.getConstructors();
+                    Constructor ctor = null;
+                    Class[] ctorParamTypes = null;
+                    
+                    for (int i=0; i < cons.length; i++)
+                    {
+                        Class[] ctorTypes = cons[i].getParameterTypes();
+
+                        if (OgnlRuntime.areArgsCompatible(values, ctorTypes)
+                            && (ctor == null || OgnlRuntime.isMoreSpecific(ctorTypes, ctorParamTypes))) {
+                            ctor = cons[i];
+                            ctorParamTypes = ctorTypes;
+                        }
+                    }
+
+                    if (ctor == null)
+                        ctor = OgnlRuntime.getConvertedConstructorAndArgs(context, clazz, OgnlRuntime.getConstructors(clazz), values, new Object[values.length]);
+
+                    if (ctor == null)
+                        throw new NoSuchMethodException("Unable to find constructor appropriate for arguments in class: " + clazz);
+
+                    ctorParamTypes = ctor.getParameterTypes();
+
+                    // now loop over child values again and build up the actual source string
+
+                    for(int i = 0; i < _children.length; i++) {
+                        if (i > 0) {
+                            result = result + ", ";
+                        }
+
+                        String value = expressions[i];
+
+                        if (types[i].isPrimitive()) {
+
+                            String literal = OgnlRuntime.getNumericLiteral(types[i]);
                             if (literal != null)
                                 value += literal;
                         }
 
-                        if (objValue != null && !objValue.getClass().isPrimitive()
-                                   && !objValue.getClass().isArray() && !ASTConst.class.isInstance(_children[i])) {
-                            
-                            value = "(" + OgnlRuntime.getCompiler().getInterfaceClass(objValue.getClass()).getName() + ")" + value;
-                        } else if (!ASTConst.class.isInstance(_children[i]) 
-                                   || (ASTConst.class.isInstance(_children[i]) && !context.getCurrentType().isPrimitive())) {
-                            
-                            value = " ($w) " + value;
+                        if (ctorParamTypes[i] != types[i]) {
+
+                            if (values[i] != null && !types[i].isPrimitive()
+                                && !values[i].getClass().isArray() && !ASTConst.class.isInstance(_children[i])) {
+                                
+                                value = "(" + OgnlRuntime.getCompiler().getInterfaceClass(values[i].getClass()).getName() + ")" + value;
+                            } else if (!ASTConst.class.isInstance(_children[i])
+                                       || (ASTConst.class.isInstance(_children[i]) && !types[i].isPrimitive())) {
+                                
+                                if (!types[i].isArray()
+                                    && types[i].isPrimitive() && !ctorParamTypes[i].isPrimitive())
+                                    value = "new " + ExpressionCompiler.getCastString(OgnlRuntime.getPrimitiveWrapperClass(types[i])) + "(" + value + ")";
+                                else
+                                    value = " ($w) " + value;
+                            }
                         }
-                        
+
                         result += value;
                     }
+
                 }
                 result = result + ")";
             }

File src/java/ognl/OgnlRuntime.java

             }
             result = resolver.classForName(className, context);
         }
+
+        if (result == null)
+            throw new ClassNotFoundException("Unable to resolve class: " + className);
+        
         return result;
     }
 

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

             || (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()

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

 {
     public static final String KEY = "size";
 
-    private static Root             ROOT = new Root();
+    private static Root ROOT = new Root();
+
+    public static class IntWrapper {
+        public IntWrapper(int value)
+        {
+            this.value = value;
+        }
+
+        private final int value;
+
+        public String toString()
+        {
+            return Integer.toString(value);
+        }
+
+        public boolean equals(Object o)
+        {
+            if (this == o)
+                return true;
+            if (o == null || getClass() != o.getClass())
+                return false;
+
+            IntWrapper that = (IntWrapper) o;
+
+            return value == that.value;
+        }
+    }
+
+    public static class IntObjectWrapper {
+
+        public IntObjectWrapper(Integer value)
+        {
+            this.value = value;
+        }
+
+        private final Integer value;
+
+        public String toString()
+        {
+            return value.toString();
+        }
+
+        public boolean equals(Object o)
+        {
+            if (this == o)
+                return true;
+            if (o == null || getClass() != o.getClass())
+                return false;
+
+            IntObjectWrapper that = (IntObjectWrapper) o;
+
+            return value.equals(that.value);
+        }
+    }
 
     private static Object[][]       TESTS = {
             { "@java.lang.Class@forName(\"java.lang.Object\")", Object.class },
             { "@org.ognl.test.objects.Root@getStaticInt()", new Integer(Root.getStaticInt()) },
             { "new org.ognl.test.objects.Simple(property).getStringValue()", new Simple().getStringValue() },
             { "new org.ognl.test.objects.Simple(map['test'].property).getStringValue()", new Simple().getStringValue() },
-            { "map.test.getCurrentClass(@org.ognl.test.StaticsAndConstructorsTest@KEY.toString())", "size stop"}
+            { "map.test.getCurrentClass(@org.ognl.test.StaticsAndConstructorsTest@KEY.toString())", "size stop"},
+            { "new org.ognl.test.StaticsAndConstructorsTest$IntWrapper(index)", new IntWrapper(ROOT.getIndex()) },
+            { "new org.ognl.test.StaticsAndConstructorsTest$IntObjectWrapper(index)", new IntObjectWrapper(ROOT.getIndex()) },
     };
 
     /*===================================================================