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

NullPointerException in MVELRuntime.execute() #18

Open
binghuawu opened this issue Jul 20, 2011 · 1 comment
Open

NullPointerException in MVELRuntime.execute() #18

binghuawu opened this issue Jul 20, 2011 · 1 comment

Comments

@binghuawu
Copy link

Hi Mike,

It seems the version after 2.0.19 (excluding) will experiencing a NullPointerException.
Here is the test case to reproduce the problem:

public class X {
private String name;
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
}

public static void main(String... args) {
    String exp = "@{name == empty ? 'N/A' : name }";

    CompiledTemplate t = TemplateCompiler.compileTemplate(exp);

    Object o = TemplateRuntime.execute(t, new X());   // This line will throw the exception
    System.out.println(o);

}
And the stack trace:
java.lang.NullPointerException
at org.mvel2.MVELRuntime.execute(MVELRuntime.java:59)
at org.mvel2.compiler.CompiledExpression.getValue(CompiledExpression.java:128)
at org.mvel2.compiler.CompiledExpression.getValue(CompiledExpression.java:118)
at org.mvel2.MVEL.executeExpression(MVEL.java:928)
at org.mvel2.templates.res.CompiledTerminalExpressionNode.eval(CompiledTerminalExpressionNode.java:41)
at org.mvel2.templates.TemplateRuntime.execute(TemplateRuntime.java:286)
at org.mvel2.templates.TemplateRuntime.execute(TemplateRuntime.java:282)
at org.mvel2.templates.TemplateRuntime.execute(TemplateRuntime.java:244)
at org.mvel2.templates.TemplateRuntime.execute(TemplateRuntime.java:164)

Version 2.0.19 or earlier versions don't have such problem.

@binghuawu
Copy link
Author

Currently, I have to workaround it with @if @else like this:
@if{name == empty}@else{}@{name}@EnD{}

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