'validate a Jexl script under "compile" terms?

See this example:

public class JexlStuff {

    private static final JexlEngine jexl = new JexlBuilder().cache(512).strict(true).silent(false)
            .safe(true).create();

    public static void main(String[] args) {
        JexlScript script = jexl.createScript("var x ='6'; ");

        // populate the context
        JexlContext context = new MapContext();

        Object result = script.execute(context);
        System.out.println(result);
        if (result != null)
            System.out.println(result.getClass());

    }
}

This example prints "6" (why?). But there is no return statement. Is it some kind of configuration that will make the above example throw an error, since the script provided could never be "compiled"?

Best scenario for me, this line throws an error:

JexlScript script = jexl.createScript("var x ='6'; ");

Is there a way to validate - check syntax of the given script?

FYI:

<dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-jexl3</artifactId>
    <version>3.2.1</version>
</dependency>


Solution 1:[1]

Jexl is a scripting (JSR223) language,

var x ='6'; is a valid script, so no invalid compilation should be thrown

When setting value in script's last line the results is the output, for example in Jexl (github) test

final JexlEngine sjexl = new JexlBuilder().sandbox(sandbox).safe(false).strict(true).create();
final JexlScript set = sjexl.createScript("foo[x] = y", "foo", "x", "y");
result = set.execute(null, foo, 0, "42");
Assert.assertEquals("42", result);

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1