Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ClassCastException in/with nested Binary operation #346

Open
kmosakowski opened this issue Nov 23, 2023 · 0 comments
Open

ClassCastException in/with nested Binary operation #346

kmosakowski opened this issue Nov 23, 2023 · 0 comments

Comments

@kmosakowski
Copy link

kmosakowski commented Nov 23, 2023

Hi,
I have been investigating the problem with ClassCastExceiton related to Binary operation.

pom.xml

<dependency>
    <groupId>org.mvel</groupId>
    <artifactId>mvel2</artifactId>
    <version>2.5.0.Final</version>
</dependency>

MVEL Code snippet:

...
if(isdef aaa){
    aaaBB = aaa;
    ccc = (aaa >> 4) & 15;
    ddd = aaa & 15;
    eee = (aaa >> 16) & 15;
    fff = (aaa >> 8) & 63;
    ggg = (aaa >> 24) & 63;
}
...

We will focus only on this line
(aaa >> 4) & 15
but the problem is with all similar lines!

In the above line we have sub statement aaa >> 4 which is executed before the whole line. In every step I highlight it

There are two steps:

Compilation step BinaryOperation.class:

1. aaa >> 4
    operation=9
    Left: ASTNode=aaa, egressType=Object
    Right: LiteralNode=4, rType=106, egressType=Integer

2. (aaa >> 4) & 15
    operation=6
    Left: Substatement=(aaa >> 4), lType=106 egressType=Integer
    Right: LiteralNode=15, rType=106, egressType=Integer

Execution step MathProcessor.class:

1. aaa >> 4
    operation=9
    type1=107
    val1:
        aaa=1086456579 Long
    val2:
        4 Integer
   
    MathProcessor.class
        if (val2 instanceof Integer) {
            return (Long)val1 >> (Integer)val2;
        }
   
    Result: 67903536

2. (aaa >> 4) & 15
    operation=6
    type1=106
    val1:
        a(aaa >> 4)aa=67903536 Long
    val2:
        15 Integer
   
    MathProcessor.class
        if (val2 instanceof Long) {     //false
            return (long)(Integer)val1 & (Long)val2;
        }

        return (Integer)val1 & (Integer)val2;
   
    Result: java.lang.ClassCastException

Is there something wrong with my MVEL code?
Can I somehow workaround it?
I assume that is a bug in MVEL library

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant