TAP5-2449: PropertyConduitSource can't see Java 8 default methods
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 @@
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 @@
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())
{
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 @@
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
+
+ }
}
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";
+ }
+}