Hi, I was trying to expose my own functions using JEXL library. I am trying the below example.
public static class MyMath { public double cos(final double x) { return Math.cos(x); } } public static void testCustomFunction2() { try { Map<String, Object> funcs = new HashMap<String, Object>(); funcs.put("math", new MyMath()); JexlEngine jexl = new JexlBuilder().namespaces(funcs).create(); JexlContext jc = new MapContext(); jc.set("pi", Math.PI); JexlExpression e = jexl.createExpression("math:cos(pi)"); Object result = e.evaluate(jc); System.out.println("Result: " + result); } catch (JexlException e) { Throwable original = e.getCause(); System.out.println(e.getMessage()); original.printStackTrace(); //do something with the original } } which is given at below link: https://commons.apache.org/proper/commons-jexl/apidocs/org/apache/commons/jexl3/package-summary.html#usage When I run the above code, I get below exception. org.example.Main.testCustomFunction2:93@1:9 unsolvable function/method 'cos(Float)' Exception in thread "main" java.lang.NullPointerException at org.example.Main.testCustomFunction2(Main.java:100) at org.example.Main.main(Main.java:33) Can someone, please help me with this? I think, this is a supported way to use custom functions or exposing my own/wrapper functions. I am using Java 11 to run the above example. Thanks, Aditya — Aditya Kumar1 Technology Architect Precisely.com ATTENTION: -----The information contained in this message (including any files transmitted with this message) may contain proprietary, trade secret or other confidential and/or legally privileged information. Any pricing information contained in this message or in any files transmitted with this message is always confidential and cannot be shared with any third parties without prior written approval from Precisely. This message is intended to be read only by the individual or entity to whom it is addressed or by their designee. If the reader of this message is not the intended recipient, you are on notice that any use, disclosure, copying or distribution of this message, in any form, is strictly prohibited. If you have received this message in error, please immediately notify the sender and/or Precisely and destroy all copies of this message in your possession, custody or control.