You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by fm...@apache.org on 2015/01/16 15:24:20 UTC

svn commit: r1652415 - /sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/engine/runtime/RenderContextImpl.java

Author: fmeschbe
Date: Fri Jan 16 14:24:19 2015
New Revision: 1652415

URL: http://svn.apache.org/r1652415
Log:
SLING-4314 The implementation of RenderContext#resolveProperty can be slow for certain cases

Applying slightly modified patch by Radu Cotescu (thanks a lot).

Modification is to actually throw NoSuchMethodException already from findMethod
instead of first returning null, then checking and then throwing.

Modified:
    sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/engine/runtime/RenderContextImpl.java

Modified: sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/engine/runtime/RenderContextImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/engine/runtime/RenderContextImpl.java?rev=1652415&r1=1652414&r2=1652415&view=diff
==============================================================================
--- sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/engine/runtime/RenderContextImpl.java (original)
+++ sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/engine/runtime/RenderContextImpl.java Fri Jan 16 14:24:19 2015
@@ -276,9 +276,11 @@ public class RenderContextImpl implement
     }
 
     private Object getObjectProperty(Object obj, String property) {
-        Object result = getObjectNoArgMethod(obj, property);
-        if (result != null) return result;
-        return getField(obj, property);
+        try {
+            return getObjectNoArgMethod(obj, property);
+        } catch (NoSuchMethodException nsmex) {
+            return getField(obj, property);
+        }
     }
 
     private Object getField(Object obj, String property) {
@@ -295,21 +297,18 @@ public class RenderContextImpl implement
         }
     }
 
-    private Object getObjectNoArgMethod(Object obj, String property) {
+    private Object getObjectNoArgMethod(Object obj, String property) throws NoSuchMethodException {
         Class<?> cls = obj.getClass();
         Method method = findMethod(cls, property);
-        if (method != null) {
-            try {
-                method = extractMethodInheritanceChain(cls, method);
-                return method.invoke(obj);
-            } catch (Exception e) {
-                throw new SightlyRenderException(e);
-            }
+        try {
+            method = extractMethodInheritanceChain(cls, method);
+            return method.invoke(obj);
+        } catch (Exception e) {
+            throw new SightlyRenderException(e);
         }
-        return null;
     }
 
-    private Method findMethod(Class<?> cls, String baseName) {
+    private Method findMethod(Class<?> cls, String baseName) throws NoSuchMethodException {
         Method[] publicMethods = cls.getMethods();
         String capitalized = StringUtils.capitalize(baseName);
         for (Method m : publicMethods) {
@@ -326,7 +325,8 @@ public class RenderContextImpl implement
                 }
             }
         }
-        return null;
+
+        throw new NoSuchMethodException(baseName);
     }
 
     private boolean isMethodAllowed(Method method) {