You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by th...@apache.org on 2019/01/10 00:45:48 UTC
[1/2] tapestry-5 git commit: TAP5-2560: Error in GenericsUtils
affecting property access
Repository: tapestry-5
Updated Branches:
refs/heads/5.4.x 2c0edea0a -> bc7199284
TAP5-2560: Error in GenericsUtils affecting property access
Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo
Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/32fde0f8
Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/32fde0f8
Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/32fde0f8
Branch: refs/heads/5.4.x
Commit: 32fde0f8c38f89d596d78b7f2292b4a26958f484
Parents: 2c0edea
Author: Thiago H. de Paula Figueiredo <th...@arsmachina.com.br>
Authored: Wed Jan 9 00:22:53 2019 -0200
Committer: Thiago H. de Paula Figueiredo <th...@arsmachina.com.br>
Committed: Wed Jan 9 22:44:57 2019 -0200
----------------------------------------------------------------------
.../ioc/internal/util/GenericsUtils.java | 50 ++++++++++++++++----
1 file changed, 40 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/32fde0f8/commons/src/main/java/org/apache/tapestry5/ioc/internal/util/GenericsUtils.java
----------------------------------------------------------------------
diff --git a/commons/src/main/java/org/apache/tapestry5/ioc/internal/util/GenericsUtils.java b/commons/src/main/java/org/apache/tapestry5/ioc/internal/util/GenericsUtils.java
index bd834a5..3a9b5c8 100644
--- a/commons/src/main/java/org/apache/tapestry5/ioc/internal/util/GenericsUtils.java
+++ b/commons/src/main/java/org/apache/tapestry5/ioc/internal/util/GenericsUtils.java
@@ -12,8 +12,18 @@
package org.apache.tapestry5.ioc.internal.util;
-import java.lang.reflect.*;
+import java.lang.reflect.Array;
+import java.lang.reflect.Field;
+import java.lang.reflect.GenericArrayType;
+import java.lang.reflect.GenericDeclaration;
+import java.lang.reflect.Method;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.lang.reflect.TypeVariable;
+import java.lang.reflect.WildcardType;
+import java.util.ArrayList;
import java.util.LinkedList;
+import java.util.List;
/**
* Static methods related to the use of JDK 1.5 generics.
@@ -367,15 +377,7 @@ public class GenericsUtils
}
Class theClass = asClass(containingType);
- Type genericSuperclass = theClass.getGenericSuperclass();
- while (genericSuperclass != null && // true for interfaces with no superclass
- !theClass.equals(Object.class) &&
- !theClass.equals(typeVariableOwner))
- {
- stack.addFirst(genericSuperclass);
- theClass = asClass(genericSuperclass);
- genericSuperclass = theClass.getGenericSuperclass();
- }
+ addGenericSuperclasses(theClass, typeVariableOwner, stack);
int i = getTypeVariableIndex(typeVariable);
Type resolved = typeVariable;
@@ -400,6 +402,34 @@ public class GenericsUtils
return ((TypeVariable) resolved).getBounds()[0];
}
+
+ private static void addGenericSuperclasses(Class theClass, final Class typeVariableOwner, final LinkedList<Type> stack) {
+ Type genericSuperclass = theClass.getGenericSuperclass();
+ while (genericSuperclass != null && // true for interfaces with no superclass
+ !theClass.equals(Object.class) &&
+ !theClass.equals(typeVariableOwner))
+ {
+ stack.addFirst(genericSuperclass);
+ theClass = asClass(genericSuperclass);
+ genericSuperclass = theClass.getGenericSuperclass();
+ }
+ for (Type type : theClass.getGenericInterfaces()) {
+ stack.add(type);
+ }
+ for (Class implementedInterface : getAllImplementedInterfaces(theClass)) {
+ addGenericSuperclasses(implementedInterface, typeVariableOwner, stack);
+ }
+ }
+
+ private static List<Class> getAllImplementedInterfaces(Class theClass) {
+ List<Class> list = new ArrayList<>();
+ for (Class implementedInterface : theClass.getInterfaces()) {
+ list.add(implementedInterface);
+ list.addAll(getAllImplementedInterfaces(implementedInterface));
+ }
+ return list;
+ }
+
/**
* @param type - something like List<T>[] or List<? extends T>[] or T[]
* @param containingType - the shallowest type in the hierarchy where type is defined.
[2/2] tapestry-5 git commit: TAP5-2560: adding unit test.
Posted by th...@apache.org.
TAP5-2560: adding unit test.
Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo
Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/bc719928
Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/bc719928
Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/bc719928
Branch: refs/heads/5.4.x
Commit: bc7199284f049f1e8f7b2b6589b5b02014c8d634
Parents: 32fde0f
Author: Thiago H. de Paula Figueiredo <th...@arsmachina.com.br>
Authored: Wed Jan 9 22:43:33 2019 -0200
Committer: Thiago H. de Paula Figueiredo <th...@arsmachina.com.br>
Committed: Wed Jan 9 22:45:17 2019 -0200
----------------------------------------------------------------------
.../AbstractBeanModelSourceImplTest.java | 48 ++++++++++++++++++++
1 file changed, 48 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/bc719928/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/AbstractBeanModelSourceImplTest.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/AbstractBeanModelSourceImplTest.java b/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/AbstractBeanModelSourceImplTest.java
index 1294934..a3b5939 100644
--- a/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/AbstractBeanModelSourceImplTest.java
+++ b/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/AbstractBeanModelSourceImplTest.java
@@ -723,6 +723,26 @@ public abstract class AbstractBeanModelSourceImplTest extends InternalBaseTestCa
verify();
}
+ // https://issues.apache.org/jira/browse/TAP5-2560
+ @Test
+ public void missing_property_due_to_wrong_type_parameter_resolution()
+ {
+
+ Messages messages = mockMessages();
+
+ stub_contains(messages, false);
+
+ replay();
+
+ BeanModel<FileContentUnit> beanModel = source.createDisplayModel(FileContentUnit.class, messages);
+
+ // throws "org.apache.tapestry5.internal.services.PropertyExpressionException: Exception generating conduit for expression 'content.mimeType': Class org.apache.tapestry5.internal.services.AbstractBeanModelSourceImplTest$ContentData does not contain a property (or public field) named 'mimeType'." without fix
+ beanModel.add("content.mimeType");
+
+ verify();
+
+ }
+
final private static class SortableBean
{
private int sortableByDefault;
@@ -754,4 +774,32 @@ public abstract class AbstractBeanModelSourceImplTest extends InternalBaseTestCa
}
+ public interface NonTranslatableContentUnit<T extends ContentData> {
+ T getContent();
+ }
+
+ public interface BinaryContentUnit<T extends BinaryContent> extends NonTranslatableContentUnit<T> {}
+
+ public interface FileContentUnit extends BinaryContentUnit<FileContent> {}
+
+ public interface ContentData {
+ boolean isEmpty();
+ }
+
+ public interface BinaryContent extends ContentData {
+ String getMimeType();
+ }
+
+ public interface FileContent extends BinaryContent {}
+
+ public class ConcreteFileContent implements FileContentUnit {
+
+ @Override
+ public FileContent getContent() {
+ return null;
+ }
+
+ }
+
+
}