Skip to main content



      Home
Home » Language IDEs » Java Development Tools (JDT) » Dead code detection
Dead code detection [message #257614] Wed, 26 November 2008 07:54
Eclipse UserFriend
Just this week, we released a new compiler diagnostic for flagging
presence of dead code, e.g.

public class X {
void foo(int x, int[] array) {
for (int i = 0; i < array.length; i++) {
if (x == array[i])
return;
else
break;
}
}
}

will now tell you (once you enable the new compiler diagnosis) :

----------
1. WARNING in X.java (at line 3)
for (int i = 0; i < array.length; i++) {
^^^
Dead code
----------
1 problem (1 warning)

Now there is a debate, about situations where some trivial IF statements
contain dead code, like:

if (DEBUG) {
...
}

We are considering a sub-option to let the compiler tolerate such a
trivial IF check, as a known coding pattern.
If you feel strongly about what a trivial IF pattern is, I recommend you
comment into: https://bugs.eclipse.org/bugs/show_bug.cgi?id=256463

Hope you like this new diagnosis.

Note1: The compiler always silently never generates dead code into a
classfile; now it can even tell you about its presence.

Note2: Because classfiles do not contain dead code, static analysis
tools performing on classfiles (e.g. Findbugs) cannot detect these.
Previous Topic:Fixing "The jer container on the classpath is not a perfect match" yields no changes
Next Topic:Eclipse 3.4.1 java compiler creating class file with references to missing classes
Goto Forum:
  


Current Time: Sat Apr 19 11:54:04 EDT 2025

Powered by FUDForum. Page generated in 0.04025 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top