Commits

Anonymous committed ba3b5e6

Fixed ASTProperty bug that only shows up in jre 1.6. Wasn't able to resolve simple getValue() property because a hasValue() method existed.. Changed to use propery descriptor first and fall back to propertyaccessors when that is null so that actual settable/gettable properties are found first.

Comments (0)

Files changed (4)

src/java/ognl/ASTProperty.java

     protected Object getValueBody(OgnlContext context, Object source)
             throws OgnlException
     {
-        Object result = null;
-        Object property = null;
-        result = property = getProperty(context, source);
+        Object property = getProperty(context, source);
+        
+        Object result = OgnlRuntime.getProperty(context, source, property);
 
-        result = OgnlRuntime.getProperty(context, source, property);
-
-        if (result == null) {
-
+        if (result == null)
+        {
             result = OgnlRuntime.getNullHandler(OgnlRuntime.getTargetClass(source)).nullPropertyValue(context, source, property);
         }
 
         Method m = null;
 
         try {
-            /* System.out.println("astproperty is indexed? : " + isIndexedAccess() + " child: " + _children[0].getClass().getName()
+            /*System.out.println("astproperty is indexed? : " + isIndexedAccess() + " child: " + _children[0].getClass().getName()
                                + " target: " + target.getClass().getName() + " current object: " + context.getCurrentObject().getClass().getName());*/
 
             if (isIndexedAccess())
                     }
                 } else
                 {
-
-                    if (pa != null)
+                    if (pd != null)
+                    {
+                        m = pd.getReadMethod();
+                        result = "." + m.getName() + "()";
+                    } else if (pa != null)
                     {
                         Object currObj = context.getCurrentObject();
                         Class currType = context.getCurrentType();
                 if (target != null)
                     _setterClass = target.getClass();
 
-                if (_parent != null && pd != null && pa == null) {
-
+                if (_parent != null && pd != null && pa == null)
+                {
                     m = pd.getReadMethod();
                     result = m.getName() + "()";
                 } else {
 
-                    if (context.getCurrentObject().getClass().isArray()) {
+                    if (context.getCurrentObject().getClass().isArray())
+                    {
                         result = "";
-                    } else if (pa != null) {
-
+                    } else if (pa != null)
+                    {
                         Object currObj = context.getCurrentObject();
                         //Class currType = context.getCurrentType();
                         //Class prevType = context.getPreviousType();
                         //context.setCurrentType(currType);
                         //context.setPreviousType(prevType);
 
-                        if (!lastChild(context)) {
-
+                        if (!lastChild(context))
+                        {
                             result = pa.getSourceAccessor(context, context.getCurrentObject(), srcString);
-                        } else {
-
+                        } else
+                        {
                             result = pa.getSourceSetter(context, context.getCurrentObject(), srcString);
                         }
 
 
         context.setCurrentObject(target);
 
-        if (m != null) {
-
+        if (m != null)
+        {
             context.setCurrentType(m.getReturnType());
             context.setCurrentAccessor(OgnlRuntime.getCompiler().getSuperOrInterfaceClass(m, m.getDeclaringClass()));
         }

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

 package org.ognl.test;
 
 import junit.framework.TestSuite;
-import org.ognl.test.objects.BaseBean;
-import org.ognl.test.objects.Bean2;
-import org.ognl.test.objects.FirstBean;
-import org.ognl.test.objects.Root;
+import org.ognl.test.objects.*;
 
 import java.text.SimpleDateFormat;
 import java.util.Arrays;
     
     private static Root ROOT = new Root();
     private static BaseBean BEAN = new FirstBean();
+    private static PropertyHolder PROPERTY = new PropertyHolder();
 
     private static Object[][]       TESTS = {
             { ROOT, "testString != null && !false", Boolean.TRUE},
             { ROOT, "getIndexedProperty(property.bean3.map[\"bar\"])", ROOT.getArray()},
             { ROOT, "getProperty().getBean3()", ((Bean2)ROOT.getProperty()).getBean3()},
             { ROOT, "intValue", new Integer(0), new Integer(2), new Integer(2) },
-            { ROOT, "! disabled", new Boolean(true)},
-            { ROOT, "disabled", new Boolean(false), new Boolean(true), new Boolean(true)},
+            { ROOT, "! booleanValue", Boolean.TRUE},
+            { ROOT, "booleanValue", Boolean.FALSE, Boolean.TRUE, Boolean.TRUE},
             { ROOT, "! disabled", new Boolean(false)},
             { ROOT, "disabled || readonly", Boolean.TRUE},
             { ROOT, "property.bean3.value != null", Boolean.TRUE},
             { ROOT, "openTransitionWin", Boolean.FALSE},
             { ROOT, "b.methodOfB(a.methodOfA(b)-1)", new Integer(0)},
             { ROOT, "disabled", Boolean.TRUE},
+            { PROPERTY, "value", ""}
     };
 
     public static String formatValue(int millis, boolean b1, boolean b2)

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

+package org.ognl.test.objects;
+
+/**
+ * Simple class used to test various kind of property resolutions.
+ */
+public class PropertyHolder {
+
+    String _value = "";
+
+    public String getValue()
+    {
+        return _value;
+    }
+
+    public void setValue(String value)
+    {
+        _value = value;
+    }
+    
+    public boolean hasValue()
+    {
+        return _value != null && _value.length() > 0;
+    }
+}

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

     {
         return _beanProvider;
     }
-    
+
+    public boolean getBooleanValue()
+    {
+        return _disabled;
+    }
+
+    public void setBooleanValue(boolean value)
+    {
+        _disabled = value;
+    }
+
     public boolean getDisabled()
     {
         return _disabled;
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.