-
Bug
-
Resolution: Fixed
-
P4
-
8u20
-
b39
-
x86_64
-
windows_7
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8085770 | emb-9 | Attila Szegedi | P4 | Resolved | Fixed | team |
JDK-8065527 | 8u45 | Attila Szegedi | P4 | Resolved | Fixed | b01 |
JDK-8064451 | 8u40 | Attila Szegedi | P4 | Resolved | Fixed | b15 |
JDK-8070516 | emb-8u47 | Attila Szegedi | P4 | Resolved | Fixed | team |
FULL PRODUCT VERSION :
java version "1.8.0_20"
Java(TM) SE Runtime Environment (build 1.8.0_20-b26)
Java HotSpot(TM) 64-Bit Server VM (build 25.20-b23, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]
A DESCRIPTION OF THE PROBLEM :
Using the Nashorn Javascript engine, a statement that uses the logical NOT operator to negate the value return by a method defined with a boxed Boolean return type results in a NullPointerException if the returned value is null. In Javascript null is considered a falsey value, so the statement should result in a 'true' value.
!null // returns true
!myJavaObject.getNullBooleanValue() // should return true if return value is defined as Boolean and returns null
If the referenced method is defined to return Object rather than Boolean, the statement returns the expected "true" value. When defined as Boolean return type a NullPointerException is thrown.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Execute the provided test case
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
!null = true
!checkKittens = true
!profile.getNullValue() = true
!profile.isLikesKittens() = true
ACTUAL -
!null = true
!checkKittens = true
!profile.getNullValue() = true
Exception in thread "main" java.lang.NullPointerException
at sun.invoke.util.ValueConversions.unboxBoolean(Unknown Source)
at jdk.nashorn.internal.scripts.Script$\^eval\_.runScript(<eval>:1)
at jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:535)
at jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:209)
at jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:378)
at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:568)
at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:525)
at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:521)
at jdk.nashorn.api.scripting.NashornScriptEngine.eval(NashornScriptEngine.java:192)
at javax.script.AbstractScriptEngine.eval(Unknown Source)
at NashornBooleanTest.eval(NashornBooleanTest.java:22)
at NashornBooleanTest.main(NashornBooleanTest.java:18)
ERROR MESSAGES/STACK TRACES THAT OCCUR :
Exception in thread "main" java.lang.NullPointerException
at sun.invoke.util.ValueConversions.unboxBoolean(Unknown Source)
at jdk.nashorn.internal.scripts.Script$\^eval\_.runScript(<eval>:1)
at jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:535)
at jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:209)
at jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:378)
at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:568)
at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:525)
at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:521)
at jdk.nashorn.api.scripting.NashornScriptEngine.eval(NashornScriptEngine.java:192)
at javax.script.AbstractScriptEngine.eval(Unknown Source)
at NashornBooleanTest.eval(NashornBooleanTest.java:22)
at NashornBooleanTest.main(NashornBooleanTest.java:18)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import javax.script.Bindings;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
import javax.script.SimpleBindings;
public class NashornBooleanTest {
public static void main(String[] args) throws ScriptException {
ScriptEngine engine = new ScriptEngineManager().getEngineByName("javascript");
Bindings bindings = new SimpleBindings();
bindings.put("checkKittens", null);
bindings.put("profile", new Profile());
eval("!null", engine, bindings);
eval("!checkKittens", engine, bindings);
eval("!profile.getNullValue()", engine, bindings);
eval("!profile.isLikesKittens()", engine, bindings);
}
private static void eval(String statement, ScriptEngine engine, Bindings bindings) throws ScriptException {
System.out.println(statement + " = " + engine.eval(statement, bindings));
}
public static class Profile {
Boolean likesKittens;
public Boolean isLikesKittens() {
return likesKittens;
}
public Object getNullValue() {
return null;
}
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Write statement without using logical not operator (!) or change method return type to Object.
java version "1.8.0_20"
Java(TM) SE Runtime Environment (build 1.8.0_20-b26)
Java HotSpot(TM) 64-Bit Server VM (build 25.20-b23, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]
A DESCRIPTION OF THE PROBLEM :
Using the Nashorn Javascript engine, a statement that uses the logical NOT operator to negate the value return by a method defined with a boxed Boolean return type results in a NullPointerException if the returned value is null. In Javascript null is considered a falsey value, so the statement should result in a 'true' value.
!null // returns true
!myJavaObject.getNullBooleanValue() // should return true if return value is defined as Boolean and returns null
If the referenced method is defined to return Object rather than Boolean, the statement returns the expected "true" value. When defined as Boolean return type a NullPointerException is thrown.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Execute the provided test case
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
!null = true
!checkKittens = true
!profile.getNullValue() = true
!profile.isLikesKittens() = true
ACTUAL -
!null = true
!checkKittens = true
!profile.getNullValue() = true
Exception in thread "main" java.lang.NullPointerException
at sun.invoke.util.ValueConversions.unboxBoolean(Unknown Source)
at jdk.nashorn.internal.scripts.Script$\^eval\_.runScript(<eval>:1)
at jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:535)
at jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:209)
at jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:378)
at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:568)
at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:525)
at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:521)
at jdk.nashorn.api.scripting.NashornScriptEngine.eval(NashornScriptEngine.java:192)
at javax.script.AbstractScriptEngine.eval(Unknown Source)
at NashornBooleanTest.eval(NashornBooleanTest.java:22)
at NashornBooleanTest.main(NashornBooleanTest.java:18)
ERROR MESSAGES/STACK TRACES THAT OCCUR :
Exception in thread "main" java.lang.NullPointerException
at sun.invoke.util.ValueConversions.unboxBoolean(Unknown Source)
at jdk.nashorn.internal.scripts.Script$\^eval\_.runScript(<eval>:1)
at jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:535)
at jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:209)
at jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:378)
at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:568)
at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:525)
at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:521)
at jdk.nashorn.api.scripting.NashornScriptEngine.eval(NashornScriptEngine.java:192)
at javax.script.AbstractScriptEngine.eval(Unknown Source)
at NashornBooleanTest.eval(NashornBooleanTest.java:22)
at NashornBooleanTest.main(NashornBooleanTest.java:18)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import javax.script.Bindings;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
import javax.script.SimpleBindings;
public class NashornBooleanTest {
public static void main(String[] args) throws ScriptException {
ScriptEngine engine = new ScriptEngineManager().getEngineByName("javascript");
Bindings bindings = new SimpleBindings();
bindings.put("checkKittens", null);
bindings.put("profile", new Profile());
eval("!null", engine, bindings);
eval("!checkKittens", engine, bindings);
eval("!profile.getNullValue()", engine, bindings);
eval("!profile.isLikesKittens()", engine, bindings);
}
private static void eval(String statement, ScriptEngine engine, Bindings bindings) throws ScriptException {
System.out.println(statement + " = " + engine.eval(statement, bindings));
}
public static class Profile {
Boolean likesKittens;
public Boolean isLikesKittens() {
return likesKittens;
}
public Object getNullValue() {
return null;
}
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Write statement without using logical not operator (!) or change method return type to Object.
- backported by
-
JDK-8064451 Logical NOT operator throws NullPointerException for null Boolean return values
-
- Resolved
-
-
JDK-8065527 Logical NOT operator throws NullPointerException for null Boolean return values
-
- Resolved
-
-
JDK-8070516 Logical NOT operator throws NullPointerException for null Boolean return values
-
- Resolved
-
-
JDK-8085770 Logical NOT operator throws NullPointerException for null Boolean return values
-
- Resolved
-
- is blocked by
-
JDK-8060483 NPE with explicitCastArguments unboxing null
-
- Closed
-