2

I am using eclipse Luna 4.4 I think it is not showing me warning for dead code.

It shows error for

if(false){
// Shows warning for dead code here
System.out.println("Dead Code");
}

but it doesn't show any warning if i say

boolean b = false;
if(b){
// Doesn't show warning for dead code here
System.out.println("Dead Code");
}

Somehow I have a little memory that it was giving warning on previous version don't know exactly which.

Once I was doing like

boolean b = false;
// code here
// forgot to make it true in some case
if(b){// do things here}  // this gave me warning.

Do anyone know what happend here or is there any setting in preferences that can do this. Thank you in advance.

Foolish
  • 3,952
  • 33
  • 46
  • 2
    because b value can change at runtime in second case.. in first case its compile time. – virendrao Apr 29 '15 at 12:23
  • FWIW, Eclipse Kepler does not warn either. Are you sure it was Eclipse that gave that warning (not FindBugs or something)? – Thilo Apr 29 '15 at 12:25
  • @Thilo - Not sure if it should warn.... I believe `b` is being assigned some value in the *some code here part*. – TheLostMind Apr 29 '15 at 12:26
  • You do get a dead code warning for the very similar `Boolean b = null; if (b != null){}`. – Thilo Apr 29 '15 at 12:29
  • 2
    This could've been a feature of an additional plugin, that was installed to your eclipse. F.e. [findbugs](http://findbugs.sourceforge.net/) can do some static code analysis to highlight such mistakes. By default without similar plugins, I don't think any eclipse version can locate your case #2. – SME_Dev Apr 29 '15 at 12:30
  • Don't remember, I was on friend's PC. It could be findbugs. I was not aware of findbugs though. Thanks. – Foolish Apr 29 '15 at 12:41
  • Possible duplicate of [Why does Java have an "unreachable statement" compiler error?](http://stackoverflow.com/questions/3795585/why-does-java-have-an-unreachable-statement-compiler-error) – sauumum Jun 18 '16 at 21:22

0 Answers0