I am using Eclipse Helios IDE for our Web Application development. Under Problems section in Eclipse, for some of lines the description is displayed as "Dead Code".
Could anybody please tell me what does Dead Code actually mean ?
Please see the screen shot for your reference.
For example this part is shown as dead code under Eclipse
else { int length; if (ar != null) length = Array.getLength(ar); else length = 0; // This line is dead code
A dead code is just a warning message native to Eclipse or another compiler. It is not displayed in the javac core java compiler. On the other hand, the unreachable code is an error reported by the javac Java compiler. It is officially included in java as an error.
The quickest way to find dead code is to use a good IDE. Delete unused code and unneeded files. In the case of an unnecessary class, Inline Class or Collapse Hierarchy can be applied if a subclass or superclass is used. To remove unneeded parameters, use Remove Parameter.
Logically dead code are branches of software that cannot be reached given the logical conditions. Finding logically dead code is important because it can indicate the software was not written as originally intended. So simply, a code change made the branch no longer necessary.
In Eclipse, "dead code" is code that will never be executed. Usually it's in a conditional branch that logically will never be entered.
A trivial example would be the following:
boolean x = true; if (x) { // do something } else { // this is dead code! }
It's not an error, because it's still valid java, but it's a useful warning, especially if the logical conditions are complex, and where it may not be intuitively obvious that the code will never be executed.
In your specific example, Eclipse has calculated that ar
will always be non-null, and so the else length = 0
branch will never be executed.
And yes, it's possible that Eclipse is wrong, but it's much more likely that it's not.
Dead code is code that will never be executed, e.g.
boolean b = true if (!b) { .... // dead code here }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With