I am trying to use BigDecimal Literal in expression String
I am using JEXL 2.1.1
I am using literal suffix 'h' as mentioned in http://commons.apache.org/jexl/reference/syntax.html#Literals

JexlEngine expressionFactory = new JexlEngine();
JexlContext context = new MapContext();
context.set ( "a", new BigDecimal( "0.0002" ));
Expression expression = expressionFactory.createExpression(" a > 42.0h "  );
boolean result=(Boolean)expression.evaluate( context );

I am getting below exception

org.apache.commons.jexl2.JexlException$Parsing: h@1:24 parsing error near '... , missing  ...'
at             org.apache.commons.jexl2.parser.JexlParser.jjtreeCloseNodeScope(JexlParser.java:126)
at org.apache.commons.jexl2.parser.Parser.ExpressionStatement(Parser.java:274)
at org.apache.commons.jexl2.parser.Parser.Statement(Parser.java:140)
at org.apache.commons.jexl2.parser.Parser.JexlScript(Parser.java:72)
at org.apache.commons.jexl2.parser.Parser.parse(Parser.java:24)
at org.apache.commons.jexl2.JexlEngine.parse(JexlEngine.java:1248)
at org.apache.commons.jexl2.JexlEngine.createExpression(JexlEngine.java:435)
at org.apache.commons.jexl2.JexlEngine.createExpression(JexlEngine.java:419)
有帮助吗?

解决方案

It looks like a documentation bug. Correct Big Decimal Suffix is 'B' (Instead of 'H' )
Correct Big Integer Suffix is 'H' (Instead of 'B')
This can be clearly verified by looking at ASTNumberLiteral.java

I have raised this issue https://issues.apache.org/jira/browse/JEXL-141

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top