Bug 282768 - [compiler] Dead code detection should ignore trivial case for ternary if operator
Summary: [compiler] Dead code detection should ignore trivial case for ternary if oper...
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.5   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: 3.6 M1   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-07-07 23:41 EDT by Peter Becker CLA
Modified: 2009-08-05 01:13 EDT (History)
2 users (show)

See Also:


Attachments
Proposed fix (6.51 KB, patch)
2009-07-15 12:03 EDT, Olivier Thomann CLA
no flags Details | Diff
Proposed fix + updated regression test (7.64 KB, patch)
2009-07-15 13:06 EDT, Olivier Thomann CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
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