Bug 319510 - dead code detection vs assert
Summary: dead code detection vs assert
Status: VERIFIED DUPLICATE of bug 173725
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.7   Edit
Hardware: Macintosh Mac OS X - Carbon (unsup.)
: P3 normal (vote)
Target Milestone: 3.6 M6   Edit
Assignee: Ayushman Jain CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-07-12 03:20 EDT by Adriaan Peeters CLA
Modified: 2010-09-14 07:28 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Adriaan Peeters CLA 2010-07-12 03:20:17 EDT
Build Identifier: 20100617-1415

The following code results in a Dead code warning for the else clause. When this clause is removed however, the code fails to compile because of a missing return. Maybe asserts should be ignored for dead code detection, or otherwise, make it configurable.

	private boolean assertTest(Object foo) {
		assert foo instanceof String;
		if (foo != null) {
			return true;
		} else {
			return false;
		}
	}

Reproducible: Always
Comment 1 Ayushman Jain CLA 2010-07-12 04:22:18 EDT
(In reply to comment #0)
> Build Identifier: 20100617-1415
> 
> The following code results in a Dead code warning for the else clause. When
> this clause is removed however, the code fails to compile because of a missing
> return. Maybe asserts should be ignored for dead code detection, or otherwise,
> make it configurable.

I think you're incorrect when you remove the else clause because of the dead code warning. If you see the quick fix eclipse offers you corresponding to the dead code warning - it says "Remove(including condition)". Selecting this removes the else statement AND the if clause as well. And there's no missing return warning for the method.

You can argue that the "redundant null check" warning is incorrect because the asserts is not necessarily present at runtime. But the strategy we follow vis-a-vis asserts is that we don't elicit null warnings inside assert statements, but we do use the null info generated in an assert statement in further analaysis. See bug 173725.
Comment 2 Ayushman Jain CLA 2010-08-16 06:48:16 EDT
we're clear about this now - we do want to use the null info from the assert expression in further analysis.

*** This bug has been marked as a duplicate of bug 173725 ***
Comment 3 Srikanth Sankaran CLA 2010-08-26 03:14:50 EDT
Verified for 3.6.1 RC2
Comment 4 Satyam Kandula CLA 2010-09-14 07:28:32 EDT
I do agree that dead code warning is good, but the code is getting optimized and it differs from the behavior that javac exhibits. Hence I opened bug 325229 to track care of it. 
As this bug talks about warning, I am marking this verified. 

Verified for 3.7M2 using build I20100909-1700