tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Fedd Kraft <>
Subject Re: Why AstValue (part of EL) coerces set value to the target type
Date Mon, 09 May 2011 10:08:57 GMT
09.05.2011 3:50, Konstantin Kolinko пишет:
> 2011/5/7 Fedd Kraft<>:
>> Hi,
>> I think I have problems in my software because the implementation of EL
>> works so that the set value is coerced to the target type.
>> I am talking about lines 153-157 of the class org.apache.el.parser
>> <>.AstValue.
>> I guess it makes sence all the time except if the 'base' is the Map. I seem
>> that once I put a String into the Map, I lose the ability to put, say, an
>> array or a Collection there through the setValue method of the
>> ValueExpression.
>> The ValueExpressioni s a property of the Map, like this ${map.key}. If this
>> expression is String, I can't setValue a Collection there, my collection
>> becomes a String through toString method, because the resolver.getType
>> method returns the Class of what is currently kept under this key.
>> Please tell me whether this is an intended/unavoidable behaviour, or a bug?
> I think you can file a bug, but please provide a working example that
> reproduces the issue.
> If I see it correctly, reading "expression_language-2_2-mrel-spec.pdf"
> 1) ch. says
> "In the case of lvalues, the expected type is ignored and the provided value is
> coerced to the actual type of the property the expression points to, before that
> property is set."
> 2) assigning of a value to a map entry should be handled by
> MapELResolver, which Javadoc is in ch.2.15. The getType() call there
> is documented to return Object.class.
> Implementation of javax.el.ELResolver#getType() in trunk performs a
> bit differently.
> BTW, a workaround in your case might be to do assignment in two steps:
>   first assign null, and then assign the actual value.
> Best regards,
> Konstantin Kolinko


I'll try to prepare a reproducing example a bit later if I can...

unfortunately I can't even set the value of an expression (with setValue 
method) to null, as null gets coerced to an empty String.

Is far as I recall, approximately two years ago it worked as I expected, 
then I guess the map resolver was changed to return a type of the value 
kept instead of Object.class, and it was made for some reason.

Anymay, thanks, Konstantin, I'll try it some other way.

(happy Victory Day BTW :)


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message