Bug 80630

Summary: [1.5] Conditional expression unboxing should handle this case
Product: [Eclipse Project] JDT Reporter: Olivier Thomann <Olivier_Thomann>
Component: CoreAssignee: Philipe Mulet <philippe_mulet>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3    
Version: 3.1   
Target Milestone: 3.1 M5   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Olivier Thomann CLA 2004-12-09 14:35:48 EST
Test case:
public class X {
	public static void main(String[] args) {
		boolean b = true;
		Character _Character = new Character(' ');
		char c = ' ';
		Integer _Integer = new Integer(2);
		if ((b ? _Character : _Integer) == c) {
			System.out.println("SUCCESS");
		} else {
			System.out.println("FAILURE");
		}
	}
}

javac can successfully compile it. It converts the _Character to its charValue()
and the _Integer to its intValue().

We fail with:

----------
1. ERROR in C:\tests_sources\X.java (at line 7)
	if ((b ? _Character : _Integer) == c) {
	    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Incompatible operand types Object and char
----------
1 problem (1 error)

Note that it doesn't work anymore if you extract the conditional expression in a
local variable of type Object.
Comment 1 Philipe Mulet CLA 2005-02-08 17:25:00 EST
As soon as both operands are numeric using unboxing, conditional operator is
unboxing both operands. So bool ? Integer : Character ==> bool ? int : char.
We were incorrectly letting it use the reference type scenario instead.

Added AutoboxingTest#test095-096
Fixed
Comment 2 Jerome Lanneluc CLA 2005-02-15 07:29:21 EST
Verified in I20050214