Commits

Anonymous committed 0d709b2

Fixes OGNL-94. Incorrect widening expressions on ASTTest when expression types are already compatible.

  • Participants
  • Parent commits ca390f4

Comments (0)

Files changed (5)

File src/java/ognl/ASTAdd.java

                 context.setCurrentType(_getterClass);
             }
 
-            //if (context.getCurrentType() == null)
-              //  context.setCurrentType(Double.TYPE);
+            try {
+
+                Object contextObj = getValueBody(context, target);
+                context.setCurrentObject(contextObj);
+
+            } catch (Throwable t) {
+                // ignore
+            }
 
             return result;
 

File src/java/ognl/ASTChain.java

             if ((_children != null) && (_children.length > 0)) {
                 for(int i = 0; i < _children.length; i++) {
                     
-                   /*  System.out.println("astchain child: " + _children[i].getClass().getName()
+                     /*System.out.println("astchain child: " + _children[i].getClass().getName()
                                        + " with current object target " + context.getCurrentObject()
-                                       + " current type: " + context.getCurrentType()); */
+                                       + " current type: " + context.getCurrentType());*/
 
                     String value = _children[i].toGetSourceString(context, context.getCurrentObject());
                     

File src/java/ognl/ASTTest.java

         
         try {
 
-            String first = OgnlRuntime.getChildSource(context, target, _children[0]);
+            String first = OgnlRuntime.getChildSource(context, target, _children[0]);            
             if (!OgnlRuntime.isBoolean(first) && !context.getCurrentType().isPrimitive())
                 first = OgnlRuntime.getCompiler().createLocalReference(context, first, context.getCurrentType());
             if (ExpressionNode.class.isInstance(_children[0])) {
             }
             
             String second = OgnlRuntime.getChildSource(context, target, _children[1]);
+            Class secondType = context.getCurrentType();
+
             if (!OgnlRuntime.isBoolean(second) && !context.getCurrentType().isPrimitive())
                 second = OgnlRuntime.getCompiler().createLocalReference(context, second, context.getCurrentType());
             if (ExpressionNode.class.isInstance(_children[1])) {
             }
 
             String third = OgnlRuntime.getChildSource(context, target, _children[2]);
+            Class thirdType = context.getCurrentType();
+            
             if (!OgnlRuntime.isBoolean(third) && !context.getCurrentType().isPrimitive())
                 third = OgnlRuntime.getCompiler().createLocalReference(context, third, context.getCurrentType());
             if (ExpressionNode.class.isInstance(_children[2])) {
                 third = "(" + third + ")";
             }
 
+            boolean mismatched = (secondType.isPrimitive() && !thirdType.isPrimitive())
+                                || (!secondType.isPrimitive() && thirdType.isPrimitive()) ? true : false;
+
             result += "ognl.OgnlOps.booleanValue(" + first + ")";
 
             result += " ? ";
 
-            result += " ($w) " + second;
+            result += (mismatched ? " ($w) " : "") + second;
             result += " : ";
 
-            result += " ($w) " + third;
+            result += (mismatched ? " ($w) " : "") + third;
 
             context.setCurrentObject(target);
             context.setCurrentType(Object.class);

File src/java/ognl/NumericExpression.java

  */
 package ognl;
 
+import ognl.enhance.ExpressionCompiler;
 import ognl.enhance.UnsupportedCompilationException;
 
 
         if (context.getCurrentType() != null && !context.getCurrentType().isPrimitive()
             && context.getCurrentObject() != null && Number.class.isInstance(context.getCurrentObject()))
         {
-            ret = "((" + OgnlRuntime.getCompiler().getClassName(context.getCurrentObject().getClass()) + ")" + ret + ")";
+            ret = "((" + ExpressionCompiler.getCastString(context.getCurrentObject().getClass()) + ")" + ret + ")";
             ret += "." + OgnlRuntime.getNumericValueGetter(context.getCurrentObject().getClass());
         } else if (context.getCurrentType() != null && context.getCurrentType().isPrimitive()) {
             

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

             { ROOT, " !(printDelivery || @Boolean@FALSE)", Boolean.FALSE},
             { ROOT, "openTransitionWin", Boolean.FALSE},
             { ROOT, "b.methodOfB(a.methodOfA(b)-1)", new Integer(0)},
-            { ROOT, "genericIndex-1", new Integer(1)}
+            { ROOT, "genericIndex-1", new Integer(1)},
+            { ROOT, "((renderNavigation ? 0 : 1) + map.size) * theInt", new Integer(((ROOT.getRenderNavigation() ? 0 : 1 ) + ROOT.getMap().size()) * ROOT.getTheInt())}
     };
 
     public static String formatValue(int millis, boolean b1, boolean b2)