typetools / typetools/checker-framework

False positive when invoking abstract method of a enum

Open
#5,165 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dataflow False Positive (false warning or imprecision)
Dominant language
Java
Stars
1.1k
Forks
440
Avg merge
1d 12h
Merged PRs (30d)
134

Description

When referring a enum value with abstract method, checker framework use annotation on method declaration instead of method override.

Command

$ checker/bin/javac -processor nullness EnumExplicit.java

Input

File: ./EnumExplicit.java

class EnumExplicit {

    public static enum EnumWithMethod {
        VALUE {
            @Override
            public void call(@Nullable String string) {
                // Null string is acceptable in this function.
            }
        };

        public abstract void call(String string);
    }

    public static void main(String[] args) {
        EnumWithMethod.VALUE.call(null);
    }

}

Output

EnumExplicit.java:18: error: [argument] incompatible argument for parameter string of call.
        EnumWithMethod.VALUE.call(null);
                                  ^
  found   : null (NullType)
  required: @Initialized @NonNull String
1 error

version output:

javac 11.0.13
git.branch=master
git.build.host=buffalo.cs.washington.edu
git.build.user.email=
git.build.user.name=Michael Ernst
git.build.version=3.22.2
git.closest.tag.commit.count=6005
git.closest.tag.name=after-reformatting
git.commit.id=c67a31b6f1a7e01ec6347e032d85bed76bdebdc1
git.commit.id.abbrev=c67a31b
git.commit.id.describe=after-reformatting-6005-gc67a31b-dirty
git.commit.message.full=Add citations\n
git.commit.message.short=Add citations
git.commit.time=2022-06-14T10\:51\:59-0700
git.commit.user.email=mernst@cs.washington.edu
git.commit.user.name=Michael Ernst
git.dirty=true
git.remote.origin.url=/scratch/mernst/cf-release/interm/checker-framework
git.tags=
git.total.commit.count=17419
Note: Checker Framework 3.22.2

Expectation

Checkers framework should allow function call in example instead of reporting an error.

When referring a specific enum value, check framework should use annotations on override methods of that value, instead of annotations on abstract method that is overridden.

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 with checker/bin/javac -processor nullness EnumExplicit.java using the enum example in EnumExplicit.java. Trace how the nullness checker resolves annotations for EnumWithMethod.VALUE.call, then add a regression test showing that the override's @Nullable parameter is used and the invocation succeeds.

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.