Skip to content

return value not always returned #7

Description

@sdyura

here is some code:


private static void runJShellBindingExample2() {
        try {
            ScriptEngineManager manager = new ScriptEngineManager();
            ScriptEngine engine = manager.getEngineByName("jshell");

            String script = "" +
                    "if (inputA != null && inputB != null) {" +
                    "   System.out.println(\"Input A: \" + inputA);" +
                    "   System.out.println(\"Input B: \" + inputB);" +
                    "   var output = inputA + \" \" + inputB;" +
                    "   System.out.println(\"GOING TO RETURN: \" + output);" +
                    "   return output;" +
                    "}" +
                    "return \"\"";

            engine.put("inputA", "hello");
            engine.put("inputB", "world");

            Object result = engine.eval(script);
            System.out.println("runJShellBindingExample2 Result: " + result);

            Object output = engine.get("output");
            System.out.println("Output Variable: " + output);

        } catch (ScriptException e) {
            e.printStackTrace();
        }
    }

when i run it i get this back:

Input A: hello
Input B: world
GOING TO RETURN: hello world
runJShellBindingExample2 Result: 
Output Variable: null

even though i would expect to get:

Input A: hello
Input B: world
GOING TO RETURN: hello world
runJShellBindingExample2 Result: **hello world**
Output Variable: null

(tested on version 1.1.0)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

wontfixThis will not be worked on

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions