Bug 26585 - Wrong code generation in conditional expression
Summary: Wrong code generation in conditional expression
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 2.1   Edit
Hardware: PC Windows 2000
: P3 critical (vote)
Target Milestone: 2.1 M4   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-11-18 09:16 EST by Olivier Thomann CLA
Modified: 2002-12-17 07:28 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Olivier Thomann CLA 2002-11-18 09:16:35 EST
Using M3, the following bug has been reported on EC:

Javac and eclipse compiler don't behave the same on this code:

public class NullOuvert {
    public static final boolean VIER_BUBEN = false;
    public static final String SPIEL = VIER_BUBEN ? "Grand Hand" : null;
    public static void main(String[] args) {
        System.out.println(SPIEL == null);
        System.out.println(SPIEL.equals(null));
        System.out.println(SPIEL);
    }
}

When running Eclipse compiler bytecodes:
false
false
null


When running javac bytecodes:
true
Exception in thread "main" java.lang.NullPointerException
        at NullOuvert.main(NullOuvert.java:6)

This is a serious problem.

A workaround seems to be to cast the null literal in a String. Then they behave
the same.
Comment 1 Philipe Mulet CLA 2002-11-18 10:59:08 EST
The casting work-around only turns off the constant inlining (would have 
achieved the same effect by removing the final flag on VIER_BUBEN).

Fixed constant code generation to disable inlining String value of null 
constant (case where target type is String). Target Object type was already 
doing the same.
Comment 2 Philipe Mulet CLA 2002-11-19 09:15:38 EST
Took out null constants completely, these are not legite anyway.
Fixed
Comment 3 David Audel CLA 2002-12-17 07:28:50 EST
Verified.