[ https://issues.apache.org/jira/browse/WW-5497?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Sebastian Götz updated WW-5497: ------------------------------- Description: When using non-static methods of class objects in OGNL expressions, the evaluation fails in {code:java} com.opensymphony.xwork2.ognl.SecurictyMemberAccess.isAccessible{code} because only static members and constructors are allowed at this location. {code:java} if (target != null) { // Special case: Target is a Class object but not Class.class if (Class.class.equals(target.getClass()) && !Class.class.equals(target)) { if (!isStatic(member) && !Constructor.class.equals(member.getClass())) { throw new IllegalArgumentException("Member expected to be static or constructor!"); } if (!member.getDeclaringClass().equals(target)) { throw new IllegalArgumentException("Target class does not match member!"); } target = null; // This information is not useful to us and conflicts with following logic which expects target to be null or an instance containing the member // Standard case: Member should exist on target } else if (!member.getDeclaringClass().isAssignableFrom(target.getClass())) { throw new IllegalArgumentException("Member does not exist on target!"); } }{code} In my concrete use-case I want to access the name of the class of an object from within the UI rendering with a simple OGNL expression: {noformat} <s:property value="#attr.node.type.name"/>{noformat} The object is on the stack and found by the ValueStack and resolve to java.lang.Object.class. Access to the getName() method is failing in this line {code:java} if (!isStatic(member) && !Constructor.class.equals(member.getClass()) {code} Is this the desired behavior or is the implementation not considering class objects having non-static members as well? was: When using non-static methods of class objects in OGNL expressions, the evaluation fails in {code:java} com.opensymphony.xwork2.ognl.SecurictyMemberAccess.isAccessible{code} because only static members and constructors are allowed at this location. {code:java} if (target != null) { // Special case: Target is a Class object but not Class.class if (Class.class.equals(target.getClass()) && !Class.class.equals(target)) { if (!isStatic(member) && !Constructor.class.equals(member.getClass())) { throw new IllegalArgumentException("Member expected to be static or constructor!"); } if (!member.getDeclaringClass().equals(target)) { throw new IllegalArgumentException("Target class does not match member!"); } target = null; // This information is not useful to us and conflicts with following logic which expects target to be null or an instance containing the member // Standard case: Member should exist on target } else if (!member.getDeclaringClass().isAssignableFrom(target.getClass())) { throw new IllegalArgumentException("Member does not exist on target!"); } }{code} In my concrete use-case I want to access the name of the class of an object from within the UI rendering with a simple OGNL expression: {noformat} <s:property value="#attr.node.type.name"/>{noformat} The object is on the stack and found by the ValueStack and is failing in this line {code:java} if (!isStatic(member) && !Constructor.class.equals(member.getClass()) {code} Is this the desired behavior or is the implementation not considering class objects having non-static members as well? > Access to non-static members of class objects fails with > IllegalArgumentException > --------------------------------------------------------------------------------- > > Key: WW-5497 > URL: https://issues.apache.org/jira/browse/WW-5497 > Project: Struts 2 > Issue Type: Bug > Components: Value Stack > Affects Versions: 6.7.0 > Reporter: Sebastian Götz > Priority: Major > > When using non-static methods of class objects in OGNL expressions, the > evaluation fails in > {code:java} > com.opensymphony.xwork2.ognl.SecurictyMemberAccess.isAccessible{code} > because only static members and constructors are allowed at this location. > > {code:java} > if (target != null) { > // Special case: Target is a Class object but not Class.class > if (Class.class.equals(target.getClass()) && !Class.class.equals(target)) > { > if (!isStatic(member) && > !Constructor.class.equals(member.getClass())) { > throw new IllegalArgumentException("Member expected to be static > or constructor!"); > } > if (!member.getDeclaringClass().equals(target)) { > throw new IllegalArgumentException("Target class does not match > member!"); > } > target = null; // This information is not useful to us and conflicts > with following logic which expects target to be null or an instance > containing the member > // Standard case: Member should exist on target > } else if > (!member.getDeclaringClass().isAssignableFrom(target.getClass())) { > throw new IllegalArgumentException("Member does not exist on > target!"); > } > }{code} > > In my concrete use-case I want to access the name of the class of an object > from within the UI rendering with a simple OGNL expression: > {noformat} > <s:property value="#attr.node.type.name"/>{noformat} > The object is on the stack and found by the ValueStack and resolve to > java.lang.Object.class. Access to the getName() method is failing in this line > {code:java} > if (!isStatic(member) && !Constructor.class.equals(member.getClass()) {code} > Is this the desired behavior or is the implementation not considering class > objects having non-static members as well? -- This message was sent by Atlassian Jira (v8.20.10#820010)