typetools / typetools/checker-framework

Anonymous inner class and @MonotonicNonNull

Open
#294 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Not sure if this is a bug or a misunderstanding on my part, but I think I'm 
getting a false positive.  Using Checker Framework v1.7.1 on Java 1.7.0_25, on 
Mac OS X 10.8.5.

    /*>>> import checkers.nullness.quals.MonotonicNonNull; */

    abstract class Monotonic
    {
        public /*@MonotonicNonNull*/String header;

        public void f()
        {
            if (header == null) {
                write("null");
            }
            else {
                runWithRetry(new Runnable() {
                    public void run() {
                        write(header);  // <-- error here
                    }
                });
            }
        }

        public abstract void write(String s);
        public abstract void runWithRetry(Runnable r);
    }

I expected no errors, but I got one:

# java -jar binary/checkers.jar -processor checkers.nullness.NullnessChecker 
Monotonic.java
Monotonic.java:15: error: incompatible types in argument.
                    write(header);
                          ^
  found   : @Initialized @MonotonicNonNull String
  required: @Initialized @NonNull String
1 error

If I replace the runWithRetry and the anonymous inner class with a simple 
"write(header)", there are no errors.

Original issue reported on code.google.com by kan...@cakoose.com on 18 Dec 2013 at 1:39

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

Reproduce the report from the Monotonic.java example with binary/checkers.jar and checkers.nullness.NullnessChecker using the supplied command. Trace how the anonymous Runnable affects the @MonotonicNonNull header and determine whether the diagnostic is expected; done means documenting the behavior or resolving it with a regression case.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.