You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ra...@apache.org on 2017/09/13 12:22:30 UTC
svn commit: r1808232 - in
/sling/trunk/bundles/scripting/sightly/compiler/src:
main/java/org/apache/sling/scripting/sightly/compiler/util/ObjectModel.java
test/java/org/apache/sling/scripting/sightly/util/ObjectModelTest.java
Author: radu
Date: Wed Sep 13 12:22:30 2017
New Revision: 1808232
URL: http://svn.apache.org/viewvc?rev=1808232&view=rev
Log:
SLING-7123 - ObjectModel does not correctly analyse all super types when solving methods
* ignored NoSuchMethodExceptions thrown by #getClassMethod so that all super types can be
analysed when looking for public methods
Modified:
sling/trunk/bundles/scripting/sightly/compiler/src/main/java/org/apache/sling/scripting/sightly/compiler/util/ObjectModel.java
sling/trunk/bundles/scripting/sightly/compiler/src/test/java/org/apache/sling/scripting/sightly/util/ObjectModelTest.java
Modified: sling/trunk/bundles/scripting/sightly/compiler/src/main/java/org/apache/sling/scripting/sightly/compiler/util/ObjectModel.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/sightly/compiler/src/main/java/org/apache/sling/scripting/sightly/compiler/util/ObjectModel.java?rev=1808232&r1=1808231&r2=1808232&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/sightly/compiler/src/main/java/org/apache/sling/scripting/sightly/compiler/util/ObjectModel.java (original)
+++ sling/trunk/bundles/scripting/sightly/compiler/src/main/java/org/apache/sling/scripting/sightly/compiler/util/ObjectModel.java Wed Sep 13 12:22:30 2017
@@ -417,7 +417,7 @@ public final class ObjectModel {
return declaringClass != Object.class || TO_STRING_METHOD.equals(method.getName());
}
- private static Method extractMethodInheritanceChain(Class type, Method method) throws NoSuchMethodException {
+ private static Method extractMethodInheritanceChain(Class type, Method method) {
if (method == null || Modifier.isPublic(type.getModifiers())) {
return method;
}
@@ -432,11 +432,15 @@ public final class ObjectModel {
return getClassMethod(type.getSuperclass(), method);
}
- private static Method getClassMethod(Class<?> type, Method method) throws NoSuchMethodException {
- Method parentMethod = type.getMethod(method.getName(), method.getParameterTypes());
- parentMethod = extractMethodInheritanceChain(parentMethod.getDeclaringClass(), parentMethod);
- if (parentMethod != null) {
- return parentMethod;
+ private static Method getClassMethod(Class<?> type, Method method) {
+ try {
+ Method parentMethod = type.getMethod(method.getName(), method.getParameterTypes());
+ parentMethod = extractMethodInheritanceChain(parentMethod.getDeclaringClass(), parentMethod);
+ if (parentMethod != null) {
+ return parentMethod;
+ }
+ } catch (NoSuchMethodException e) {
+ // ignore - maybe we don't have access to that method or the method does not belong to the current type
}
return null;
}
Modified: sling/trunk/bundles/scripting/sightly/compiler/src/test/java/org/apache/sling/scripting/sightly/util/ObjectModelTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/sightly/compiler/src/test/java/org/apache/sling/scripting/sightly/util/ObjectModelTest.java?rev=1808232&r1=1808231&r2=1808232&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/sightly/compiler/src/test/java/org/apache/sling/scripting/sightly/util/ObjectModelTest.java (original)
+++ sling/trunk/bundles/scripting/sightly/compiler/src/test/java/org/apache/sling/scripting/sightly/util/ObjectModelTest.java Wed Sep 13 12:22:30 2017
@@ -19,7 +19,6 @@
package org.apache.sling.scripting.sightly.util;
import java.util.Arrays;
-import java.util.Calendar;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
@@ -130,6 +129,7 @@ public class ObjectModelTest {
@Test
public void testResolveProperty() {
+ assertEquals(0, ObjectModel.resolveProperty(Collections.EMPTY_LIST, "size"));
assertNull(ObjectModel.resolveProperty(null, null));
Integer[] testArray = new Integer[] {1, 2, 3};
assertEquals(2, ObjectModel.resolveProperty(testArray, 1));