struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Adam Hardy <ahardy.str...@cyberspaceroad.com>
Subject Re: OGNL ClassCastException
Date Mon, 16 Feb 2009 00:14:43 GMT
Correct me if I'm wrong but this looks like a fundamental class mismatch.

I can see in struts-default.xml that both Sets and Collections are configured to 
be accessed by the same PropertyAccessor.

 From debugging, I can see OGNL picks the PropertyAccessor for Collections to 
deal with my target property. Logical, since the ArrayList is an implementation 
of Collection.

The problem is that struts has registered XWorkCollectionPropertyAccessor as the 
PropertyAccessor for Collections, but this extends ognl.SetPropertyAccessor 
which tries to cast the property to java.util.Set with the resulting 
ClassCastException.

I noticed in an xwork jira that this seems to have happened before:

http://jira.opensymphony.com/browse/XW-310

but that's fixed - unfortunately not helping me though.

I can work around this by copying XWorkCollectionPropertyAccessor and writing a 
method to deal with Collections rather than Sets, but this is surely a bug. I'm 
just wondering why no-one else is suffering with it.




Adam Hardy on 14/02/09 13:35, wrote:
> Yes, it is a JPA entity bean proxied by OpenJPA.
> 
> It has a list property - the bean is a parent in a parent-child 
> relationship and this property is the list of children.
> 
> This is the incoming HTTP parameter:
> 
> portfolio.weightings[0]=123
> 
> Despite debugging it I am still not sure what has happened but I do see 
> that OgnlRuntime looks up the appropriate PropertyAccessor in a map, and 
> gets the wrong one back (SetPropertyAccessor instead of 
> ListPropertyAccessor).
> 
> Is there anything I can do to influence that?
> 
> 
> Regards
> Adam
> 
> Musachy Barroso on 13/02/09 17:10, wrote:
>> It seems like it is not a list but a proxy to it
>> "org.apache.openjpa.util.java$util$ArrayList$proxy" which could be the
>> root of the problem.
>>
>> musachy
>>
>> On Fri, Feb 13, 2009 at 12:00 PM, Adam Hardy
>> <ahardy.struts@cyberspaceroad.com> wrote:
>>> I have a situation where OGNL seems to be misinterpreting the class 
>>> of the
>>> HTTP parameter property it is setting during the ParameterInterceptor 
>>> call.
>>>
>>> As you can see from the exception message, the object is an ArrayList 
>>> and
>>> certainly not a Set which OGNL thinks it is. I have double, triple and
>>> quadruple checked that I am not using a Set at this point.
>>>
>>> How and where is OGNL deciding that this is a Set? And can I 
>>> configure it?
>>>
>>> The HTTP parameter is 'myParameter[0]' and the List is a generic, 
>>> assuming
>>> that makes a difference.
>>>
>>>
>>> java.lang.ClassCastException:
>>> org.apache.openjpa.util.java$util$ArrayList$proxy cannot be cast to
>>> java.util.Set
>>>        at 
>>> ognl.SetPropertyAccessor.getProperty(SetPropertyAccessor.java:46)
>>>        at
>>> com.opensymphony.xwork2.ognl.accessor.XWorkCollectionPropertyAccessor.getProperty(XWorkCollectionPropertyAccessor.java:80)

>>>
>>>        at ognl.OgnlRuntime.getProperty(OgnlRuntime.java:1643)
>>>        at ognl.ASTProperty.getValueBody(ASTProperty.java:92)
>>>        at ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:170)
>>>        at ognl.SimpleNode.getValue(SimpleNode.java:210)


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Mime
View raw message