Bug 26585

Summary: Wrong code generation in conditional expression
Product: [Eclipse Project] JDT Reporter: Olivier Thomann <Olivier_Thomann>
Component: CoreAssignee: Philipe Mulet <philippe_mulet>
Status: VERIFIED FIXED QA Contact:
Severity: critical    
Priority: P3    
Version: 2.1   
Target Milestone: 2.1 M4   
Hardware: PC   
OS: Windows 2000   
Whiteboard:

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.