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

Suspected bug, expected PropertyAccessException but got NPE. #326

Open
elevenching opened this issue Apr 25, 2023 · 1 comment
Open

Suspected bug, expected PropertyAccessException but got NPE. #326

elevenching opened this issue Apr 25, 2023 · 1 comment

Comments

@elevenching
Copy link

I am not sure if this is a bug, but I encountered this situation while using the software. It does not occur consistently.

For an expression like "$.result.success," the data being accessed might have a "result" value or not. After compiling the expression using MVEL.compileExpression, I use MVEL.executeExpression to obtain the value. If the current data does not have a "result" value, I expect it to throw a PropertyAccessException, but instead, I get a NullPointerException (NPE).

Upon tracing the code, I found a suspicious part.

In ASTNode, there is a variable "protected transient volatile Accessor accessor;" with the "volatile" modifier. When I try to execute the expression from data without a "result" value and trace it to ASTNode, I find that the accessor already exists. As a result, it attempts to access the values in the order of "$," "result," and "success." Since "result" does not exist, it throws an NPE.

Actually, the expectation was that the accessor would not exist, and during the construction of the accessor, a PropertyAccessException would be thrown due to the null "result" value.

Therefore, I suspect that the issue is caused by the "volatile" modifier, which makes the accessor visible to other threads during concurrent execution, leading to the problem described above.

@linux2014linux
Copy link

linux2014linux commented Sep 8, 2023

@elevenching Could you provide some example code?

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

2 participants