typetools / typetools/checker-framework

Boolean variables aliased to data-flow facts in type refinement

Open
#406 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dataflow enhancement
Dominant language
Java
Stars
1.1k
Forks
440
Avg merge
1d 12h
Merged PRs (30d)
134

Description

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

See more test cases in #6296.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Test.java reproducer and run the javac command shown with NullnessChecker; compare its current diagnostic with the requested behavior. Review the additional cases referenced in #6296, and consider the work done when a boolean alias such as test refines o to non-null inside the conditional without the incompatible-argument error.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
compilers
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.