Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

NullPointerException in MVELRuntime.execute() #18

Open
binghuawu opened this Issue · 1 comment

1 participant

@binghuawu

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

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
Something went wrong with that request. Please try again.