Bug 282768

Summary: [compiler] Dead code detection should ignore trivial case for ternary if operator
Product: [Eclipse Project] JDT Reporter: Peter Becker <peter>
Component: CoreAssignee: Olivier Thomann <Olivier_Thomann>
Status: VERIFIED FIXED QA Contact:
Severity: enhancement    
Priority: P3 CC: Olivier_Thomann, srikanth_sankaran
Version: 3.5   
Target Milestone: 3.6 M1   
Hardware: All   
OS: All   
Whiteboard:
Attachments:
Description Flags
Proposed fix
none
Proposed fix + updated regression test none

Description Peter Becker CLA 2009-07-07 23:41:55 EDT
The new dead code detection feature in Galileo warns about this bit of code:

private static final boolean ALLOW_DOMAIN_LITERALS = false;
private static final String domain = ALLOW_DOMAIN_LITERALS ? rfc2822Domain : rfc1035DomainName;

Since the true branch of the ternary if can not be reached, this is correct, but somehow it should be classified as trivial and thus treated in the same manner as this code:

private static final boolean ALLOW_DOMAIN_LITERALS = false;
private static final String domain;
static {
    if(ALLOW_DOMAIN_LITERALS) {
        domain = rfc2822Domain;
    } else {
        domain= rfc1035DomainName;
    }
}

This second version is ignored. Treating the ternary if different seems inconsistent and putting compile-time configuration into static final booleans seems a common enough case to justify special treatment.
Comment 1 Olivier Thomann CLA 2009-07-15 12:02:43 EDT
If we support the trivial if as a special case, we should also support the conditional expression.
Comment 2 Olivier Thomann CLA 2009-07-15 12:03:13 EDT
Created attachment 141659 [details]
Proposed fix

I'll add regression test for this.
Comment 3 Olivier Thomann CLA 2009-07-15 13:06:02 EDT
Created attachment 141670 [details]
Proposed fix + updated regression test

I updated the test org.eclipse.jdt.core.tests.compiler.regression.CastTest#test036
Comment 4 Olivier Thomann CLA 2009-07-15 13:39:44 EDT
Released for 3.6M1.
Updated existing regression test.
Comment 5 Satyam Kandula CLA 2009-08-04 11:19:57 EDT
Verified for 3.6M1 using build I20090802-2000