PropertyExpressionEvaluation returns null for certain generics

Description

I have a Stripes project where my domain objects have several layers of generics. It seems that in a certain combination, calling PropertyExpressionEvaluation.getType() returns null. This seems to be the simplest scenario where it fails:

Main.java

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 import net.sourceforge.stripes.util.bean.PropertyExpression; import net.sourceforge.stripes.util.bean.PropertyExpressionEvaluation; public final class Main { public static void main(final String... args) throws Throwable { printType(new Bean(), "listValues"); printType(new Bean(), "listValues.values"); printType(new Bean(), "listValues.values[0]"); printType(new Bean(), "listValues.values[0].alpha"); printType(new Bean(), "listValues.values[0].beta"); } private static void printType(Object bean, String expression) { PropertyExpression exp = PropertyExpression.getExpression(expression); PropertyExpressionEvaluation eval = new PropertyExpressionEvaluation( exp, bean); Class<?> clazz = eval.getType(); System.out.println("Expression: " + expression); System.out.println("Object: " + bean); System.out.println("Type: " + clazz); System.out.println(); } }

Bean.java

1 2 3 public class Bean { public ListValues<Child> getListValues() { return null; } }

ListValues.java

1 2 3 public class ListValues<V> { public java.util.List<V> getValues() { return null; } }

Parent.java

1 2 3 4 public class Parent<A> { public A getAlpha() { return null; } public Beta getBeta() { return null; } }

Child.java

1 public class Child extends Parent<Alpha> {}

Alpha.java

1 public class Alpha {}

Beta.java

1 public class Beta {}

Running Main prints the following output:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 Expression: listValues Object: Bean@4d20a47e Type: class ListValues Expression: listValues.values Object: Bean@2b86c6b2 Type: interface java.util.List Expression: listValues.values[0] Object: Bean@593d93f4 Type: class Child Expression: listValues.values[0].alpha Object: Bean@635b9e68 Type: null Expression: listValues.values[0].beta Object: Bean@13fcf0ce Type: class Beta

Without understanding the PropertyExpressionEvaluation code too much, I think the problem is at the following line:

PropertyExpressionEvaluation.java

1 2 3 type = getBeanPropertyType(clazz, property); // XXX What do we do if type is a generic type?

The type returned by getBeanPropertyType() is a TypeVariable and, according to the comment, it seems like this scenario isn't handled yet. For now, I guess I can just create a few concrete classes without using so many generics... but it would be nice if this worked. Maybe my test classes will help someone figure out the correct logic?

Environment

None

Status

Assignee

Unassigned

Reporter

Martin Cortez

Labels

Tester

None

Components

Affects versions

Release 1.5.7

Priority

Major
Configure