You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
CompileException on seemingly valid MVEL. Adding two extra semi-colons after closing else if block curly brace resolves exception; one is not enough.
#342
Open
ScottCUSA opened this issue
Sep 20, 2023
· 1 comment
MVEL throws a CompileException when passing valid MVEL to org.mvel2.MVEL.evalToString.
port = 'ae1';
if (port.contains('-')) {
port = port.substring(port.indexOf('-') + 1);
} else if (port.startsWith('ae')) {
port = port.replace('ae', 'lag-');
}
port = port.toLowerCase();
return port;
This is the exception:
org.mvel2.CompileException: [Error: unexpected token or unknown identifier:port.toLowerCase()]
[Near : {... sWith('ae')) {port = port.replace('ae', 'lag-');} port = port.toLowerCase(); ....}]
^
[Line: 1, Column: 156]
at org.mvel2.MVELInterpretedRuntime.parseAndExecuteInterpreted(MVELInterpretedRuntime.java:149) ~[jaxws-api-2.3.1.jar:?]
at org.mvel2.MVELInterpretedRuntime.parse(MVELInterpretedRuntime.java:58) ~[jaxws-api-2.3.1.jar:?]
at org.mvel2.MVEL.eval(MVEL.java:170) ~[jaxws-api-2.3.1.jar:?]
at org.mvel2.MVEL.evalToString(MVEL.java:349) ~[jaxws-api-2.3.1.jar:?]]
...
If I add two semi-colons to the end of the if block immediately proceeding the "unexpected token" it works without issue.
port = 'ae1';
if (port.contains('-')) {
port = port.substring(port.indexOf('-') + 1);
} else if (port.startsWith('ae')) {
port = port.replace('ae', 'lag-');
} ;; /* THESE TWO SEMI-COLONS RESOLVE COMPILE EXCEPTION */
port = port.toLowerCase();
return port;
result = lag-1
The text was updated successfully, but these errors were encountered:
I attempted to determine what was going on by debugging the AbstractParser while running on the example code. I don't know enough about how it's supposed to work to determine how to fix it.
From what I can tell it looks like there's a "null" value on the parser stack when it should be empty prior to evaluating the expression port = port.toUpperCase()
When adding the two extra semi-colons it looks like the parser stack is cleared prior to it starting to parse port = port.toLowerCase();
ScottCUSA
changed the title
CompileException on seemingly valid MVEL, adding extra semi-colons resolves exception
CompileException seemingly valid MVEL. Adding two extra semi-colons after closing else if block curly brace resolves exception; one is not enough.
Jan 9, 2024
ScottCUSA
changed the title
CompileException seemingly valid MVEL. Adding two extra semi-colons after closing else if block curly brace resolves exception; one is not enough.
CompileException on seemingly valid MVEL. Adding two extra semi-colons after closing else if block curly brace resolves exception; one is not enough.
Jan 9, 2024
MVEL throws a CompileException when passing valid MVEL to
org.mvel2.MVEL.evalToString
.This is the exception:
If I add two semi-colons to the end of the if block immediately proceeding the "unexpected token" it works without issue.
result = lag-1
The text was updated successfully, but these errors were encountered: