Commits

Anonymous committed b5d0fc1

Fixes OGNL-113. ObjectPropertyAccessor wasn't handling the case where an object would return null from toString(). This is questionable but whatever..

Comments (0)

Files changed (6)

src/java/ognl/ObjectPropertyAccessor.java

             String methodName = index.toString().replaceAll("\"", "");
             Method m = OgnlRuntime.getWriteMethod(target.getClass(), methodName);
 
-            if (m == null && context.getCurrentObject() != null)
+            if (m == null && context.getCurrentObject() != null
+                && context.getCurrentObject().toString() != null)
+            {
                 m = OgnlRuntime.getWriteMethod(target.getClass(), context.getCurrentObject().toString().replaceAll("\"", ""));
+            }
 
             if (m == null)
                 return "";

src/test/java/org/ognl/test/NullHandlerTest.java

 
 public class NullHandlerTest extends OgnlTestCase
 {
-
     private static CorrectedObject CORRECTED = new CorrectedObject();
 
     private static Object[][] TESTS = {
             // NullHandler
-            { CORRECTED, "stringValue", "corrected" }, 
+            { CORRECTED, "stringValue", "corrected" },
             { CORRECTED, "getStringValue()", "corrected" },
-            { CORRECTED, "#root.stringValue", "corrected" }, 
+            { CORRECTED, "#root.stringValue", "corrected" },
             { CORRECTED, "#root.getStringValue()", "corrected" },
-            };
+    };
 
     /*
      * =================================================================== Public static methods
             if (TESTS[i].length == 3) {
                 result
                         .addTest(new NullHandlerTest((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 NullHandlerTest((String) TESTS[i][1], TESTS[i][0], (String) TESTS[i][1],
-                            TESTS[i][2], TESTS[i][3]));
+                                                       TESTS[i][2], TESTS[i][3]));
                 } else {
                     if (TESTS[i].length == 5) {
                         result.addTest(new NullHandlerTest((String) TESTS[i][1], TESTS[i][0], (String) TESTS[i][1],
-                                TESTS[i][2], TESTS[i][3], TESTS[i][4]));
+                                                           TESTS[i][2], TESTS[i][3], TESTS[i][4]));
                     } else {
                         throw new RuntimeException("don't understand TEST format");
                     }
     }
 
     public NullHandlerTest(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/NullStringCatenationTest.java

         for (int i = 0; i < TESTS.length; i++) {
             if (TESTS[i].length == 3) {
                 result.addTest(new NullStringCatenationTest((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 NullStringCatenationTest((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 NullStringCatenationTest((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");
                     }

src/test/java/org/ognl/test/PrimitiveNullHandlingTest.java

     }
 
     private static Object[][] TESTS = {
-    // Primitive null handling
+            // Primitive null handling
             { SIMPLE, "floatValue", new Float(10.56f), null, new Float(0f) }, // set float to
-                                                                                // null, should
-                                                                                // yield 0.0f
+            // null, should
+            // yield 0.0f
             { SIMPLE, "intValue", new Integer(34), null, new Integer(0) },// set int to null,
-                                                                            // should yield 0
+            // should yield 0
             { SIMPLE, "booleanValue", Boolean.FALSE, Boolean.TRUE, Boolean.TRUE },// set boolean
-                                                                                    // to TRUE,
-                                                                                    // should yield
-                                                                                    // true
+            // to TRUE,
+            // should yield
+            // true
             { SIMPLE, "booleanValue", Boolean.TRUE, null, Boolean.FALSE }, // set boolean to null,
-                                                                            // should yield false
-           
+            // should yield false
+
     };
 
     /*
         for(int i = 0; i < TESTS.length; i++) {
             if (TESTS[i].length == 3) {
                 result.addTest(new PrimitiveNullHandlingTest((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 PrimitiveNullHandlingTest((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 PrimitiveNullHandlingTest((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");
                     }
     }
 
     public PrimitiveNullHandlingTest(String name, Object root, String expressionString, Object expectedResult,
-            Object setValue, Object expectedAfterSetResult)
+                                     Object setValue, Object expectedAfterSetResult)
     {
         super(name, root, expressionString, expectedResult, setValue, expectedAfterSetResult);
     }
 
     public PrimitiveNullHandlingTest(String name, Object root, String expressionString, Object expectedResult,
-            Object setValue)
+                                     Object setValue)
     {
         super(name, root, expressionString, expectedResult, setValue);
     }

src/test/java/org/ognl/test/SimplePropertyTreeTest.java

 public class SimplePropertyTreeTest extends OgnlTestCase
 {
     private static Object[][]       TESTS = {
-                                        { "name", Boolean.TRUE },
-                                        { "foo", Boolean.TRUE },
-                                        { "name[i]", Boolean.FALSE },
-                                        { "name + foo", Boolean.FALSE },
-                                        { "name.foo", Boolean.FALSE },
-                                        { "name.foo.bar", Boolean.FALSE },
-                                        { "name.{? foo }", Boolean.FALSE },
-                                        { "name.( foo )", Boolean.FALSE }
-                                    };
+            { "name", Boolean.TRUE },
+            { "foo", Boolean.TRUE },
+            { "name[i]", Boolean.FALSE },
+            { "name + foo", Boolean.FALSE },
+            { "name.foo", Boolean.FALSE },
+            { "name.foo.bar", Boolean.FALSE },
+            { "name.{? foo }", Boolean.FALSE },
+            { "name.( foo )", Boolean.FALSE }
+    };
 
-	/*===================================================================
-		Public static methods
-	  ===================================================================*/
+    /*===================================================================
+         Public static methods
+       ===================================================================*/
     public static TestSuite suite()
     {
         TestSuite       result = new TestSuite();
         return result;
     }
 
-	/*===================================================================
-		Constructors
-	  ===================================================================*/
-	public SimplePropertyTreeTest()
-	{
-	    super();
-	}
+    /*===================================================================
+         Constructors
+       ===================================================================*/
+    public SimplePropertyTreeTest()
+    {
+        super();
+    }
 
-	public SimplePropertyTreeTest(String name)
-	{
-	    super(name);
-	}
+    public SimplePropertyTreeTest(String name)
+    {
+        super(name);
+    }
 
     public SimplePropertyTreeTest(String name, Object root, String expressionString, Object expectedResult, Object setValue, Object expectedAfterSetResult)
     {
         super(name, root, expressionString, expectedResult);
     }
 
-	/*===================================================================
-		Overridden methods
-	  ===================================================================*/
+    /*===================================================================
+         Overridden methods
+       ===================================================================*/
     protected void runTest() throws Exception
     {
         assertTrue(Ognl.isSimpleProperty(getExpression(), _context) == ((Boolean)getExpectedResult()).booleanValue());

src/test/java/org/ognl/test/objects/CorrectedObject.java

 //--------------------------------------------------------------------------
 package org.ognl.test.objects;
 
-public class CorrectedObject extends Object
+public class CorrectedObject
 {
     public CorrectedObject()
     {
-        super();
     }
 
     public void setStringValue(String value)
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.