Community
Participate
Working Groups
Bug occurs in Eclipse 2.1.2, when use ? operator with two true constant values in boolean expression. Java mistakenly evaluate first operand expression ('s.length() == 0') and raise exception. There is no this bug in Eclipse 2.1.1 and 2.1. To reproduce bug run this code: -------------------------------- public class TestEclipse { public static void main(String[] args) { String s = null; System.out.println( s != null && (s.length() == 0 ? TestConst.c1 : TestConst.c2) ); // System.out.println(s != null && (s.length() == 0 ? true : true)); } public static class TestConst { public static final boolean c1 = true; public static final boolean c2 = true; } } -------------------------------- Console: java.lang.NullPointerException at TestEclipse.main(TestEclipse.java:6) Exception in thread "main"
Reproduced.
Same problem with || operator: public class TestEclipse { public static void main(String[] args) { String s = "a"; System.out.println( s == null || (s.length() == 0 ? TestConst.c1 : TestConst.c2) ); } public static class TestConst { public static final boolean c1 = false; public static final boolean c2 = false; } }
Fixed in latest, added regression tests: BooleanTest#test011, test012, test013
Backported to 2.1 stream
Verified for 3.0M6
Verified for 2.1.3 with build M200402251535.