Dead code detection [message #257614] |
Wed, 26 November 2008 07:54 |
Eclipse User |
|
|
|
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.
|
|
|
Powered by
FUDForum. Page generated in 0.04025 seconds