Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrading from Java 7 to Java 8 breaks the "If condition" building block #251

Closed
itaiag opened this issue Oct 20, 2015 · 1 comment
Closed

Comments

@itaiag
Copy link
Contributor

itaiag commented Oct 20, 2015

The "If condition" is using a Javascript script to evaluate the condition (ifScriptCondition.js).

From some reason, when upgrading Java from version 7 to 8, the script is no longer evaluated correctly and every expression result is false.

In the terminal we see something like this:

     [echo] Check condition "${retStr}" EQUALS "foo"
       [if] ??÷ 20, 2015 7:16:19 PM com.aqua.anttask.jsystem.JSystemAntUtil getParameterValue
       [if] INFO: ScriptFile = C:\Users\agmon\Desktop\runners\runnerIssue233\ifScriptCondition.js
       [if] ??÷ 20, 2015 7:16:19 PM com.aqua.anttask.jsystem.JSystemAntUtil getParameterValue
       [if] INFO: Parameters = str <SEP> foo <SEP> EQUALS <SEP> foo <SEP> true
       [if] Checking condition: str <SEP> foo <SEP> EQUALS <SEP> foo <SEP> true
       [if] Type: str
       [if] Len: 3
       [if] Result = false

In my machine it was reproduced when upgrading from jdk1.7.0_05 to jdk1.8.0_31

The class that executes the script is JSystemScriptCondition.

@itaiag itaiag added this to the 6.1.02 milestone Oct 20, 2015
@itaiag
Copy link
Contributor Author

itaiag commented Nov 2, 2015

I've created a simple snippet that execute the script and it seems that, from some reason, the Javascript under Java 8 engine is not splitting the parameters nicely.

        ScriptEngine engine = new ScriptEngineManager().getEngineByName("nashorn");
        final String params = "str <SEP> foo <SEP> EQUALS <SEP> foo <SEP> true";
        Bindings binding = new SimpleBindings();
        binding.put("params", params);
        engine.eval(new FileReader("ifScriptCondition.js"),binding);

One option for a fix is to replace, in jhe ifScriptCondition.js file the return expression of the parseExpression function from

return [temp[0].trim(),temp[1].trim()];

to

return [temp[0].replace(separator.trim(),"").trim(),temp[1].replace(separator.trim(),"").trim()];

Example can be found in the issue#251_2 branch

@itaiag itaiag self-assigned this Nov 2, 2015
@itaiag itaiag closed this as completed Nov 5, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant