what does Dead Code mean under Eclipse IDE Problems Section

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

Leave a Comment