orphan-oss / ognl

Object Graph Navigation Library
https://orphan.software
Apache License 2.0
220 stars 78 forks source link

method with varargs invoked result exception: java.lang.ArrayStoreException #212

Closed lianyiwuming closed 1 year ago

lianyiwuming commented 1 year ago

java 1.8 ognl 3.3.0 | 3.3.4

when i execute this method, i got an exception:

java.lang.ArrayStoreException
    at java.lang.System.arraycopy(Native Method)
    at ognl.OgnlRuntime.callAppropriateMethod(OgnlRuntime.java:1943)
    at ognl.ObjectMethodAccessor.callStaticMethod(ObjectMethodAccessor.java:52)
    at ognl.OgnlRuntime.callStaticMethod(OgnlRuntime.java:1983)
    at ognl.ASTStaticMethod.getValueBody(ASTStaticMethod.java:77)
    at ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:212)
    at ognl.SimpleNode.getValue(SimpleNode.java:258)
    at ognl.Ognl.getValue(Ognl.java:586)
    at ognl.Ognl.getValue(Ognl.java:550)
    at com.dmall.devops.multicloud.common.OgnlTest.t202306261048(OgnlTest.java:30)

the method is below:

@Test
    void t202306261048() throws OgnlException {
        // buile OgnlContext
        final String ddd = "ddd";
        OgnlContext context = (OgnlContext) Ognl.createDefaultContext(ddd);

        // root set
        context.setRoot(ddd);

        StringUtils.equalsAny("dd", new String[]{"dd","aa"});
        System.out.println(Ognl.getValue(Ognl.parseExpression("@org.apache.commons.lang3.StringUtils@equalsAny('dd',new String[]{'dd'})"), context, context.getRoot()));
    }
lukaszlenart commented 1 year ago

Shouldn't you use java.lang.String like this

"@org.apache.commons.lang3.StringUtils@equalsAny('dd',new java.lang.String[]{'dd'})"

?

lianyiwuming commented 1 year ago

Shouldn't you use java.lang.String like this

"@org.apache.commons.lang3.StringUtils@equalsAny('dd',new java.lang.String[]{'dd'})"

?

I tried and got the same error. It's seem because of the varargs method. After I delete the if (method.isVarArgs()){} block in method ognl.OgnlRuntime#callAppropriateMethod , I got the right result.

harawata commented 1 year ago

@lianyiwuming ,

Are you aware that you don't need to create the array explicitly?

"@org.apache.commons.lang3.StringUtils@equalsAny('cc', 'dd', 'ee')"
lianyiwuming commented 1 year ago

@harawata oooh,yes, you are right, thx

lukaszlenart commented 1 year ago

Does this fix the problem?

lianyiwuming commented 1 year ago

Yes! It work when I use varargs instead of the array explicitly. @lukaszlenart