J2SE Version (please include all output from java -version flag):
java version "1.6.0_01"
Java(TM) SE Runtime Environment (build 1.6.0_01-b06)
Java HotSpot(TM) Client VM (build 1.6.0_01-b06, mixed mode, sharing)
Does this problem occur on J2SE 5.0.x or 6.0? Yes / No (pick one)
Yes
Operating System Configuration Information (be specific):
Microsoft Windows XP [Version 5.1.2600]
Bug Description:
RFE: Replace conditional of primitive and object to use boxing instead of unboxing
Currently using the conditional operator on a primitive and object can be very error prone.
The code below will throw a NullPointerException.
If boxing was used instead of unboxing we would not have this problem.
(Bug Report 6303028 looks like they are asking for the same things)
Workaround: box the primitives ourselves (ie in the case below use Integer c = a ? new Integer(1) : b ? new Integer(2) : null; instead)
public class Test {
public static void main(String[] args) {
boolean a = false;
boolean b = false;
Integer c = a ? 1 : b ? 2 : null;
}
}