Anonymous avatar Anonymous committed 38bc4e2

Fixes OGNL-108. ASTInstanceof wasn't setting the context type before returning.

Comments (0)

Files changed (3)

src/java/ognl/ASTInstanceof.java

     public String toGetSourceString(OgnlContext context, Object target)
     {
         try {
+
+            String ret = "";
+
+            if (ASTConst.class.isInstance(_children[0]))
+                ret = ((Boolean)getValueBody(context, target)).toString();
+            else
+                ret = _children[0].toGetSourceString(context, target) + " instanceof " + targetType;
             
-            if (ASTConst.class.isInstance(_children[0]))
-                return ((Boolean)getValueBody(context, target)).toString();
-            else
-                return _children[0].toGetSourceString(context, target) + " instanceof " + targetType;
-            
+            context.setCurrentType(Boolean.TYPE);
+
+            return ret;
+
         } catch (Throwable t)
         {
             throw OgnlOps.castToRuntime(t);

src/test/java/org/ognl/test/ClassMethodTest.java

     }
 
     public ClassMethodTest(String name, Object root, String expressionString, Object expectedResult, Object setValue,
-            Object expectedAfterSetResult)
+                           Object expectedAfterSetResult)
     {
         super(name, root, expressionString, expectedResult, setValue, expectedAfterSetResult);
     }

src/test/java/org/ognl/test/InterfaceInheritanceTest.java

 import java.util.List;
 
 public class InterfaceInheritanceTest extends OgnlTestCase {
-    
+
     private static Root ROOT = new Root();
 
     static {
     }
 
     private static Object[][] TESTS = {
-            // Interface inheritence test
             {ROOT, "myMap", ROOT.getMyMap()},
             {ROOT, "myMap.test", ROOT},
             {ROOT.getMyMap(), "list", ROOT.getList()},
             {ROOT, "map.comp.getCount(genericIndex)", Integer.valueOf(0)},
             {ROOT, "map.customList.total", Integer.valueOf(1)},
             {ROOT, "myTest.theMap['key']", "value" },
-            {ROOT, "contentProvider.hasChildren(property)", Boolean.TRUE}
+            {ROOT, "contentProvider.hasChildren(property)", Boolean.TRUE},
+            {ROOT, "objectIndex instanceof java.lang.Object", Boolean.TRUE}
     };
 
     /*
         for (int i = 0; i < TESTS.length; i++) {
             if (TESTS[i].length == 3) {
                 result.addTest(new InterfaceInheritanceTest((String) TESTS[i][1], TESTS[i][0], (String) TESTS[i][1],
-                        TESTS[i][2]));
+                                                            TESTS[i][2]));
             } else {
                 if (TESTS[i].length == 4) {
                     result.addTest(new InterfaceInheritanceTest((String) TESTS[i][1], TESTS[i][0],
-                            (String) TESTS[i][1], TESTS[i][2], TESTS[i][3]));
+                                                                (String) TESTS[i][1], TESTS[i][2], TESTS[i][3]));
                 } else {
                     if (TESTS[i].length == 5) {
                         result.addTest(new InterfaceInheritanceTest((String) TESTS[i][1], TESTS[i][0],
-                                (String) TESTS[i][1], TESTS[i][2], TESTS[i][3], TESTS[i][4]));
+                                                                    (String) TESTS[i][1], TESTS[i][2], TESTS[i][3], TESTS[i][4]));
                     } else {
                         throw new RuntimeException("don't understand TEST format");
                     }
 
         return result;
     }
-    
+
     /*
     * =================================================================== Constructors
     * ===================================================================
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.