Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 375213

Summary: [loop] Incorrect dead code reporting in simple loop
Product: [Eclipse Project] JDT Reporter: Bram Kivenko <bram>
Component: CoreAssignee: Stephan Herrmann <stephan.herrmann>
Status: CLOSED WONTFIX QA Contact:
Severity: normal    
Priority: P3 CC: srikanth_sankaran, stephan.herrmann
Version: 3.8   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard: stalebug

Description Bram Kivenko CLA 2012-03-23 15:36:07 EDT
Build Identifier: 20120216-1857

Eclipse is reporting line 10 is dead code, while it is not.  Dead code reporting is probably broken on the boolean branch analysis.  When the "if" statement is broken into if-else-if statements, the dead code warning goes away.  

This code executes correctly, but line 10 is reported as dead code:

01:	String s = null;
02:	String s2 = null;
03:	for ( int i = 0; i < 3; i++ ) {
04:	    if ( s == null || i >= 0 ) {
05:		s2 = s;
06:		s = "A";
07:	    }
08:	}
09:	if ( s2 != null ) {
10:	    System.out.println("HI");
11:	}

Interestingly, this IS evaluated correctly:

01:	String s = null;
02:	String s2 = null;
03:	for ( int i = 0; s2 == null; i++ ) {
04:	    if ( s == null || i >= 0 ) {
05:		s2 = s;
06:		s = "A";
07:	    }
08:	}
09:	if ( s2 != null ) {
10:	    System.out.println("HI");
11:	}

Because of the difficulty in confirming the dead code warning is invalid, it ultimately can contribute to coding errors.

Reproducible: Always
Comment 1 Srikanth Sankaran CLA 2012-03-24 21:24:45 EDT
Ayush/Stephan - Is this due to lack of support for correlation analysis ?
Comment 2 Stephan Herrmann CLA 2012-03-25 17:15:40 EDT
Greetings from Reston at the eve of EclipseCon :)

(In reply to comment #1)
> Ayush/Stephan - Is this due to lack of support for correlation analysis ?

I'm pretty sure this is the same issue as bug 373032.
Comment 3 Srikanth Sankaran CLA 2012-03-25 20:18:23 EDT
Thanks Stephan, after it is fully confirmed, you can close this as duplicate.
Comment 4 Stephan Herrmann CLA 2014-06-15 13:42:08 EDT
We have a few open bugs regarding flow analysis of loops, putting it into that bucket.
Comment 5 Eclipse Genie CLA 2020-03-08 04:51:55 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. As such, we're closing this bug.

If you have further information on the current state of the bug, please add it and reopen this bug. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.