Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[jdt-core-dev] Compiler diagnosis for missing/unnecessary null checks



I released an early version of compiler diagnosis for missing/unnecessary
null checks. It is not fully functional yet, but should already capture
some scenarii where local variables are misused.

Default severity is "warning", we may lower it down to "ignore" for next
integration build if testing shows it is too buggy.

e.g.
public class X {
  void foo(X x) {
    if (x == this) {
      if (x == null) {// The variable x cannot be null;
                     // it was either set to a non-null value
                     // or assumed to be non-null when last used

        x.foo(this); // The variable x can only be null;
                     // it was either set to null or checked for null
                     //when last used
      }
    }
  }
}
Not supported yet:
- complex boolean condition: if ((v == null) && v.hasMore()) { ...
- while/for conditions

Limitations:
- only works with local variables
- only perform inter-procedural static analysis (similar to variable
definite assignment rules)



Back to the top