Community
Participate
Working Groups
Another bug in the conditional operator, along the lines of Bug 117495 and Bug 122987: Source code: public class X { public static void main(String[] args) { Object x = true ? true : ""; System.out.println("value " + x + " of class " + x.getClass().getCanonicalName()); } } According to spec, x should have type Boolean, but instead it is assigned type String. A similarly bizarre String conversion happens with other arguments when the alternate return values are of incompatible literal types. For example: Object x = true ? 3.0f : false; Object x = true ? 2 : false; Object x = false ? 2 : false; In all of these cases the resulting type of x is incorrectly java.lang.String.
Problem comes from constant inlining missing the boxing conversion, and reverting by default to string conversion.
Created attachment 49388 [details] Proposed patch Patch against 3.2maintenance stream.
Created attachment 49396 [details] Better patch Patch for 3.2 maintenance
Released for 3.3M2 (HEAD) A little bit reluctant for 3.2.1, since the change is bigger than I would have preferred for pure maintenance. The patch passes all our tests. Fixed
reopening for addressing in 3.2.2 branch
Released for 3.2.2
Verified for 3.3 M2 using build I20060922-0010. Note that AutoBoxingTest#test0124() does not fail with 3.3 M1 => not sure this is a variation of this bug...
verified for 3.2.2 using build M20070112-1200