Commits

Anonymous committed 6b82c68

Made the following changes:-

1] Made getValue(..) in OgnlUtil fallback to using expression parsing instead of expression compilation if ther result is null cause expression compilation needs the expression to follow JavaBeans spec. so expression like "getText('something') will return null

2] Corrected some test case eg.
comparison of result.getClass() to ArrayList.class to (result instanceof List), cause expression compilation for some reason doesn't specifically return an ArrayList but an Arrays$ArrayList etc.

git-svn-id: http://svn.opensymphony.com/svn/xwork/branches/xwork_1-2@1823e221344d-f017-0410-9bd5-d282ab1896d7

  • Participants
  • Parent commits a8f5138
  • Branches xwork_1-2

Comments (0)

Files changed (3)

File src/java/com/opensymphony/xwork/util/OgnlUtil.java

 import com.opensymphony.xwork.XworkException;
 import com.opensymphony.xwork.config.ConfigurationManager;
 import ognl.*;
+import ognl.enhance.ExpressionAccessor;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
         if (isUseOgnlEnhancement()) {
             try {
                 Node node = Ognl.compileExpression((OgnlContext)context, root, name);
-                return node.getAccessor().get((OgnlContext)context, root);
+                Object result = node.getAccessor().get((OgnlContext)context, root);
+
+                // If we can't get the value with Ognl Enhancement, let's fall back to the default
+                // Ognl without-Enhancement, cause
+                //       node.getAccessor().get(...)
+                // only applies to expression that follow JavaBeans spec. that's how it works, so
+                // expression like 'getText(...)' will return null in this case as it's not following
+                // JavaBeans spec.
+                if (result != null) {
+                    return result;
+                }                 
             }
             catch(Exception e) {
                 log.warn("unable to get value using OGNL expression compilation mode, falling back to expression parsing", e); 

File src/test/com/opensymphony/xwork/interceptor/StaticParametersInterceptorTest.java

         interceptor.destroy();
     }
 
-    private class User {
+    public static class User {
         private String name;
 
         public String getName() {

File src/test/com/opensymphony/xwork/util/OgnlUtilTest.java

         Map context = Ognl.createDefaultContext(foo);
 
         Map props = new HashMap();
-        props.put("useful", "true");
+        props.put("useful", "false");
         OgnlUtil.setProperties(props, foo, context);
 
-        assertEquals(true, foo.isUseful());
+        assertEquals(false, foo.isUseful());
 
         props = new HashMap();
-        props.put("useful", "false");
+        props.put("useful", "true");
         OgnlUtil.setProperties(props, foo, context);
 
-        assertEquals(false, foo.isUseful());
+        assertEquals(true, foo.isUseful());
     }
 
     public void testSetPropertiesDate() {
 
         result = ActionContext.getContext().getValueStack().findValue("{\"foo\",'ruby','b','tom'}");
         foo.setIncludes((List) result);
-        assertEquals(ArrayList.class, result.getClass());
+        assertTrue(result instanceof List);
 
         assertEquals(4, foo.getIncludes().size());
         assertEquals("foo", foo.getIncludes().toArray()[0]);
         }
     }
 
-    static class TestObject {
+    public static class TestObject {
         private Integer myIntegerProperty;
         private Long myLongProperty;
         private String myStrProperty;
         }
     }
 
-    class EmailAction {
+    public class EmailAction {
         public List email = new OgnlList(Email.class);
 
         public List getEmail() {
         }
     }
 
-    class OgnlList extends ArrayList {
+    public class OgnlList extends ArrayList {
         private Class clazz;
 
         public OgnlList(Class clazz) {
         }
     }
     
-    private class MyWriteBar {
+    public class MyWriteBar {
     	private int id;
     	
     	public int getId() {