typetools / typetools/checker-framework

In stub files, <T extends Object> means <T extends @Nullable Object>

Open
#3,030 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

This might be intended behavior, but I found it surprising, and I didn't see documentation of it in the manual.

I had figured that, in a stub file, <T extends Object> would be interpreted as <T extends @NonNull Object>, as it is when compiling from source. But it seems to be interpreted as <T extends @Nullable Object>, as it is when reading an unannotated class file.

$ cat Caller.java 
import java.util.concurrent.ConcurrentHashMap;
import org.checkerframework.checker.nullness.qual.Nullable;

class Caller {
  void foo() {
    ConcurrentHashMap<@Nullable String, @Nullable String> m;
  }
}

$ cat ConcurrentHashMap.astub
package java.util.concurrent;

class ConcurrentHashMap<K extends Object, V extends Object> {}

Without the stub file, the Checker Framework uses the annotations from its built-in JDK stubs, which have the right bound:

$ checker/bin/javac -processor org.checkerframework.checker.nullness.NullnessChecker Caller.java
Caller.java:6: error: [type.argument.type.incompatible] incompatible types in type argument.
    ConcurrentHashMap<@Nullable String, @Nullable String> m;
                      ^
  found   : @Initialized @Nullable String
  required: @Initialized @NonNull Object
1 error

But when I include my stub file, the Checker Framework accepts the code, rather than rejecting it as I'd expected:

$ checker/bin/javac -processor org.checkerframework.checker.nullness.NullnessChecker -Astubs=ConcurrentHashMap.astub Caller.java
[compilation succeeds]

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 supplied Caller.java and ConcurrentHashMap.astub files, then run the two checker/bin/javac commands to reproduce the differing results with and without -Astubs. Trace the stub-file handling and compare it with the built-in JDK stubs; done means the intended bound behavior is established and covered by a regression test or documented in the manual.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
compilers
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.