typetools / typetools/checker-framework
Incorrect comment on ThreadLocal for avoiding nullness warnings
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 1.1k
- Forks
- 440
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 134
Description
According to https://github.com/typetools/jdk/blob/master/src/java.base/share/classes/java/lang/ThreadLocal.java#L84-L89 I should be able to add a warning suppression to specify a non-null type for ThreadLocal
package net.mtu.eggplant.checker;
import java.text.NumberFormat;
@SuppressWarnings("nullness:type.argument.type.incompatible") // initialValue returns non-null
public final class NonNullThreadLocal extends ThreadLocal<NumberFormat> {
@Override
protected NumberFormat initialValue() {
final NumberFormat format = NumberFormat.getInstance();
// setup the number format instance to be 2 decimal places
format.setMaximumFractionDigits(2);
format.setMinimumFractionDigits(2);
return format;
}
}
gives the following warning
/home/jpschewe/projects/checker-bugs/src/main/java/net/mtu/eggplant/checker/NonNullThreadLocal.java:6: error: [type.argument] incompatible type argument for type parameter T of ThreadLocal.
public final class NonNullThreadLocal extends ThreadLocal<NumberFormat> {
^
found : @Initialized @NonNull NumberFormat
required: [extends @Initialized @Nullable Object super null (NullType)]
After some more experimentation with this I see that the correct annotation is "@SuppressWarnings("nullness:type.argument")", so it seems that the documentation just needs to be updated.
I see that https://github.com/typetools/checker-framework/issues/1572 is open for a more permanent solution to this problem. That seems like a good thing. Although I would argue that the real problem is that ThreadLocal isn't an abstract class.
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
The issue points to JDK ThreadLocal.java lines 84-89 and identifies the incorrect nullness suppression name. Search the Checker Framework documentation for the ThreadLocal warning example, verify the wording against the reported compiler output, and update the example so the documented suppression matches the intended warning; done when the documentation no longer recommends the overly specific name.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100