typetools / typetools/checker-framework
In stub files, <T extends Object> means <T extends @Nullable Object>
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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