You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@struts.apache.org by "Lukasz Lenart (Jira)" <ji...@apache.org> on 2024/06/02 12:01:00 UTC
[jira] [Assigned] (WW-5424) ClassCastException with tag "set" when variable name has length=1
[ https://issues.apache.org/jira/browse/WW-5424?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Lukasz Lenart reassigned WW-5424:
---------------------------------
Assignee: Lukasz Lenart
> ClassCastException with tag "set" when variable name has length=1
> -----------------------------------------------------------------
>
> Key: WW-5424
> URL: https://issues.apache.org/jira/browse/WW-5424
> Project: Struts 2
> Issue Type: Bug
> Components: Core Tags
> Affects Versions: 6.4.0
> Reporter: Daniel López
> Assignee: Lukasz Lenart
> Priority: Major
> Fix For: 6.5.0
>
> Time Spent: 10m
> Remaining Estimate: 0h
>
> I think it is caused by the refactor of WW-5333
> When the tag "set" is used to define a variable whose name is of length 1, a java.lang.ClassCastException (class java.lang.Character cannot be cast to class java.lang.String ) is thrown.
>
> Test case:
> {code:java}
> // code placeholder
> <s:set var="a" value="1" /> a = <s:property value="a"/>
> <s:set var="b" value="2" scope="page" /> b = <s:property value="b" />{code}
> Expected result:
> {code:java}
> // code placeholder
> a = 1
> b = 2{code}
> actual result:
> {code:java}
> a = 1
> b ={code}
> Both "s:set" throws exception when storing the value in page context. Value of a is retrieved as it is successfully saved in default context
> Exception trace
> {code:java}
> // code placeholder
> Error setting value [2] with expression [#attr['b']]
> java.lang.ClassCastException: class java.lang.Character cannot be cast to class java.lang.String (java.lang.Character and java.lang.String are in module java.base of loader 'bootstrap')
> at org.apache.struts2.dispatcher.AttributeMap.put(AttributeMap.java:46) ~[struts2-core-6.4.0.jar:6.4.0]
> at com.opensymphony.xwork2.ognl.accessor.XWorkMapPropertyAccessor.setProperty(XWorkMapPropertyAccessor.java:130) ~[struts2-core-6.4.0.jar:6.4.0]
> at ognl.OgnlRuntime.setProperty(OgnlRuntime.java:3359) ~[ognl-3.3.4.jar:?]
> at ognl.ASTProperty.setValueBody(ASTProperty.java:134) ~[ognl-3.3.4.jar:?]
> at ognl.SimpleNode.evaluateSetValueBody(SimpleNode.java:220) ~[ognl-3.3.4.jar:?]
> at ognl.SimpleNode.setValue(SimpleNode.java:308) ~[ognl-3.3.4.jar:?]
> at ognl.ASTChain.setValueBody(ASTChain.java:227) ~[ognl-3.3.4.jar:?]
> at ognl.SimpleNode.evaluateSetValueBody(SimpleNode.java:220) ~[ognl-3.3.4.jar:?]
> at ognl.SimpleNode.setValue(SimpleNode.java:308) ~[ognl-3.3.4.jar:?]
> at ognl.Ognl.setValue(Ognl.java:829) ~[ognl-3.3.4.jar:?]
> at com.opensymphony.xwork2.ognl.OgnlUtil.ognlSet(OgnlUtil.java:585) ~[struts2-core-6.4.0.jar:6.4.0]
> at com.opensymphony.xwork2.ognl.OgnlUtil.setValue(OgnlUtil.java:522) ~[struts2-core-6.4.0.jar:6.4.0]
> at com.opensymphony.xwork2.ognl.OgnlValueStack.trySetValue(OgnlValueStack.java:258) [struts2-core-6.4.0.jar:6.4.0]
> at com.opensymphony.xwork2.ognl.OgnlValueStack.setValue(OgnlValueStack.java:245) [struts2-core-6.4.0.jar:6.4.0]
> at org.apache.struts2.components.Set.end(Set.java:113) [struts2-core-6.4.0.jar:6.4.0]
> at org.apache.struts2.views.jsp.ComponentTagSupport.doEndTag(ComponentTagSupport.java:38) [struts2-core-6.4.0.jar:6.4.0]
> {code}
> When name is of length 1, the key is created as Character not String, and it fails when trying to store in a
> AttributeMap extends AbstractMap<String, Object>
>
--
This message was sent by Atlassian Jira
(v8.20.10#820010)