typetools / typetools/checker-framework

Anonymous classes and onlyDefs

Open
#2,227 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

This small example produces an error from the Nullness Checker:

import org.checkerframework.checker.nullness.qual.Nullable;
class Test {
  @Nullable Object f;
  Runnable r = new Runnable() {
      public void run() {
          f.toString();
      }
  };
}

However, there is no way to use -AonlyDefs to check this class including all contained anonymous classes.

-AonlyDefs=Test should check a class plus all contained anonymous classes (and lambdas).
The current check for the class name in onlyDefs should be extended to also check the enclosing top-level class.
This check is in https://github.com/typetools/checker-framework/blob/master/framework/src/main/java/org/checkerframework/framework/source/SourceChecker.java method boolean shouldSkipDefs(ClassTree node)

This was raised in https://github.com/typetools/checker-framework/issues/904#issuecomment-445409730 . It is very useful to be able to select the scope of type checking, but then very surprising if anonymous classes aren't checked.

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 in framework/src/main/java/org/checkerframework/framework/source/SourceChecker.java at shouldSkipDefs(ClassTree node), and review how -AonlyDefs currently matches class names. Run the provided Nullness Checker example with -AonlyDefs=Test; done means Test and its contained anonymous classes and lambdas are checked.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
devtools
Issue type
Feature
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.