ctolkmit / checker-framework

Automatically exported from code.google.com/p/checker-framework
0 stars 0 forks source link

Limitation of data-flow / local variable refinement #406

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
It would be nice if the checker could detect that 'test' being true implies 'o' 
is non-null.

=== Test.java ===
import javax.annotation.Nullable;

abstract class Test {
  abstract @Nullable Object n();

  void f(boolean flag) {
    Object o = n();
    boolean test = o != null;
    if (test) {
      g(o);
    }
  }

  void g(Object o) {}
}
===

$ javac -version -processor 
org.checkerframework.checker.nullness.NullnessChecker Test.java
javac 1.8.0-jsr308-1.8.11
Test.java:10: error: [argument.type.incompatible] incompatible types in 
argument.
      g(o);
        ^
  found   : @Initialized @Nullable Object
  required: @Initialized @NonNull Object
1 error

Original issue reported on code.google.com by cus...@google.com on 5 Mar 2015 at 3:44

GoogleCodeExporter commented 9 years ago

Original comment by michael.ernst@gmail.com on 6 Mar 2015 at 5:20

GoogleCodeExporter commented 9 years ago

Original comment by michael.ernst@gmail.com on 6 Mar 2015 at 5:21