PropertyExpressionEvaluation returns null for certain generics
--------------------------------------------------------------

                 Key: STS-884
                 URL: http://www.stripesframework.org/jira/browse/STS-884
             Project: Stripes
          Issue Type: Bug
          Components: ActionBean Dispatching
    Affects Versions: Release 1.5.7
            Reporter: Martin Cortez


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:

{code:title=Main.java|borderStyle=solid}
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();
        }
}
{code}

{code:title=Bean.java|borderStyle=solid}
public class Bean {
        public ListValues<Child> getListValues() { return null; }
}
{code}

{code:title=ListValues.java|borderStyle=solid}
public class ListValues<V> {
        public java.util.List<V> getValues() { return null; }
}
{code}

{code:title=Parent.java|borderStyle=solid}
public class Parent<A> {
        public A getAlpha() { return null; }
        public Beta getBeta() { return null; }
}
{code}

{code:title=Child.java|borderStyle=solid}
public class Child extends Parent<Alpha> {}
{code}

{code:title=Alpha.java|borderStyle=solid}
public class Alpha {}
{code}

{code:title=Beta.java|borderStyle=solid}
public class Beta {}
{code}

Running Main prints the following output:

{noformat}
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
{noformat}

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

{code:title=PropertyExpressionEvaluation.java|borderStyle=solid}
                type = getBeanPropertyType(clazz, property);
                
                // XXX What do we do if type is a generic type?
{code}

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?

-- 
This message is automatically generated by JIRA.
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Stripes-development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-development

Reply via email to