FULL PRODUCT VERSION : java version "1.6.0_20" Java(TM) SE Runtime Environment (build 1.6.0_20-b02) Java HotSpot(TM) Client VM (build 16.3-b01, mixed mode, sharing) ADDITIONAL OS VERSION INFORMATION : Windows 7 32-bit A DESCRIPTION OF THE PROBLEM : unexpected NullPointerException after running public static void main(String[] args) { Double a = null; Double b = null; Double c = null == a ? b : 0d; } Double c = null == a ? null : 0d; will work decompiled code first piece public static void main(String args[]) { Double a = null; Double b = null; Double c = Double.valueOf(a != null ? 0.0D : b.doubleValue()); } crystal clear, why it throws a NPE second piece... Double c = null == a ? null : 0d; version public static void main(String args[]) { Double a = null; Double b = null; Double c = a != null ? Double.valueOf(0.0D) : null; } STEPS TO FOLLOW TO REPRODUCE THE PROBLEM : run the main method in the Description EXPECTED VERSUS ACTUAL BEHAVIOR : EXPECTED - c equals null ACTUAL - NullPointerException on line Double c = null == a ? b : 0d; ERROR MESSAGES/STACK TRACES THAT OCCUR : Exception in thread "main" java.lang.NullPointerException REPRODUCIBILITY : This bug can be reproduced always. ---------- BEGIN SOURCE ---------- public static void main(String[] args) { Double a = null; Double b = null; Double c = null == a ? b : 0d; } ---------- END SOURCE ---------- CUSTOMER SUBMITTED WORKAROUND : instead of public static void main(String[] args) { Double a = null; Double b = null; Double c = null == a ? b : 0d; } use Double c = null == a ? null : 0d; not much of a workaround, for often a variable is required (variable b) instead of a particular value (null)
|