TAP5-2449: PropertyConduitSource can't see Java 8 default methods
Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/91af872e Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/91af872e Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/91af872e Branch: refs/heads/master Commit: 91af872e168718b6a719154674fb802b85d7ba20 Parents: d5e4c8f Author: Jochen Kemnade <jochen.kemn...@eddyson.de> Authored: Wed Jul 13 15:27:38 2016 +0200 Committer: Jochen Kemnade <jochen.kemn...@eddyson.de> Committed: Wed Jul 13 15:27:38 2016 +0200 ---------------------------------------------------------------------- .../internal/services/PropertyAccessImpl.java | 20 +++++++++++++------- .../ioc/specs/PropertyAccessImplSpec.groovy | 14 ++++++++++++++ .../test/java/com/example/TestInterface.java | 7 +++++++ 3 files changed, 34 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/91af872e/beanmodel/src/main/java/org/apache/tapestry5/ioc/internal/services/PropertyAccessImpl.java ---------------------------------------------------------------------- diff --git a/beanmodel/src/main/java/org/apache/tapestry5/ioc/internal/services/PropertyAccessImpl.java b/beanmodel/src/main/java/org/apache/tapestry5/ioc/internal/services/PropertyAccessImpl.java index 8dd1e02..00d08e2 100644 --- a/beanmodel/src/main/java/org/apache/tapestry5/ioc/internal/services/PropertyAccessImpl.java +++ b/beanmodel/src/main/java/org/apache/tapestry5/ioc/internal/services/PropertyAccessImpl.java @@ -101,10 +101,10 @@ public class PropertyAccessImpl implements PropertyAccess List<PropertyDescriptor> descriptors = CollectionFactory.newList(); addAll(descriptors, info.getPropertyDescriptors()); - - // TAP5-921 - Introspector misses interface methods not implemented in an abstract class - if (forClass.isInterface() || Modifier.isAbstract(forClass.getModifiers()) ) - addPropertiesFromExtendedInterfaces(forClass, descriptors); + // Introspector misses: + // - interface methods not implemented in an abstract class (TAP5-921) + // - default methods (TAP5-2449) + addPropertiesFromExtendedInterfaces(forClass, descriptors); addPropertiesFromScala(forClass, descriptors); @@ -118,16 +118,22 @@ public class PropertyAccessImpl implements PropertyAccess private <T> void addAll(List<T> list, T[] array) { - list.addAll(Arrays.asList(array)); + if (array.length > 0){ + list.addAll(Arrays.asList(array)); + } } private void addPropertiesFromExtendedInterfaces(Class forClass, List<PropertyDescriptor> descriptors) throws IntrospectionException { - LinkedList<Class> queue = CollectionFactory.newLinkedList(); + Class[] interfaces = forClass.getInterfaces(); + if (interfaces.length == 0){ + return; + } + LinkedList<Class> queue = CollectionFactory.newLinkedList(); // Seed the queue - addAll(queue, forClass.getInterfaces()); + addAll(queue, interfaces); while (!queue.isEmpty()) { http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/91af872e/tapestry-ioc/src/test/groovy/ioc/specs/PropertyAccessImplSpec.groovy ---------------------------------------------------------------------- diff --git a/tapestry-ioc/src/test/groovy/ioc/specs/PropertyAccessImplSpec.groovy b/tapestry-ioc/src/test/groovy/ioc/specs/PropertyAccessImplSpec.groovy index c76817f..7fa6581 100644 --- a/tapestry-ioc/src/test/groovy/ioc/specs/PropertyAccessImplSpec.groovy +++ b/tapestry-ioc/src/test/groovy/ioc/specs/PropertyAccessImplSpec.groovy @@ -1,5 +1,6 @@ package ioc.specs +import com.example.TestInterface import java.awt.Image import java.beans.* import java.lang.reflect.Method @@ -796,4 +797,17 @@ class PropertyAccessImplSpec extends Specification { private Method findMethod(Class beanClass, String methodName) { return beanClass.methods.find { it.name == methodName } } + + + public static class TestData implements TestInterface { + } + + // TAP5-2449 + def "default method is recognized"(){ + when: + def pa = getPropertyAdapter(TestData, 'testString') + then: + pa != null + + } } http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/91af872e/tapestry-ioc/src/test/java/com/example/TestInterface.java ---------------------------------------------------------------------- diff --git a/tapestry-ioc/src/test/java/com/example/TestInterface.java b/tapestry-ioc/src/test/java/com/example/TestInterface.java new file mode 100644 index 0000000..b031857 --- /dev/null +++ b/tapestry-ioc/src/test/java/com/example/TestInterface.java @@ -0,0 +1,7 @@ +package com.example; + +public interface TestInterface { + public default String getTestString() { + return "Alpha"; + } +}