Bug 100043 - [1.5][compiler] false compiler error on ?: ternary operator with boxing
Summary: [1.5][compiler] false compiler error on ?: ternary operator with boxing
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Linux
: P3 minor (vote)
Target Milestone: 3.1.1   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 106499 (view as bug list)
Depends on:
Blocks:
 
Reported: 2005-06-14 14:32 EDT by Alexey Radul CLA
Modified: 2005-09-26 09:50 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Alexey Radul CLA 2005-06-14 14:32:03 EDT
The following code is perfectly legal in java 1.5, javac compiles it,
and it runs.  It was not legal in java 1.4, and the Eclipse built-in 
compiler flags line 5 as an error, with the message
"Incompatible conditional operand types int and String"

public class Bug {
  public static void main(String[] args) {
    int foo = 0;
    String bar = "zero";
    System.out.println( (foo != 0) ? foo : bar );
  }
}
Comment 1 Philipe Mulet CLA 2005-07-04 07:45:02 EDT
Indeed, we did miss this scenario. Boxing is indicated in this case.
Added AutoboxingTest#test109.
Comment 2 Philipe Mulet CLA 2005-07-04 07:45:15 EDT
Fixed
Comment 3 Igor Galchevsky CLA 2005-07-06 04:52:40 EDT
is it possible to turn off that kind of error? Most of my code does not compiles
due to this bug.
Comment 4 Philipe Mulet CLA 2005-07-06 05:34:58 EDT
You could insert an ugly cast to workaround the bug.
We will try to post you some patch.

public class X {
  public static void main(String[] args) {
    int foo = 0;
    String bar = "zero";
    System.out.println( (foo != 0) ? (Integer)foo : bar );
  }
}
Comment 5 Maxime Daniel CLA 2005-08-09 07:59:42 EDT
Verified in 3.2 M1 with build I20050808-2000.
Comment 6 Olivier Thomann CLA 2005-08-09 13:13:49 EDT
*** Bug 106499 has been marked as a duplicate of this bug. ***
Comment 7 David Audel CLA 2005-09-26 09:50:07 EDT
Verified using M20050923-1430 for 3.1.1