Community
Participate
Working Groups
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
(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.
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 ***
Verified for 3.6.1 RC2
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