typetools / typetools/checker-framework
@KeyFor refinement doesn't work for autoboxed types
Open
@wmdietl is already working on this.
Since Nov 14, 2017.
bug
Dataflow
False Positive (false warning or imprecision)
- Dominant language
- Java
- Stars
- 1.1k
- Forks
- 440
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 134
Description
Environment: Checker Framework 1.9.11, Oracle JDK 1.8.0_65, Windows 7/8.1
Example:
import java.util.Map;
public abstract class KeyForRefinement {
public void working1(Object key) {
Map<Object, Object> m = getObjectMap();
if (!m.containsKey(key)) {
m.put(key, new Object());
}
m.get(key).toString();
}
public void working2(Integer key) {
Map<Integer, Object> m = getIntegerMap();
if (!m.containsKey(key)) {
m.put(key, new Object());
}
m.get(key).toString();
}
public void working3(Double key) {
Map<Double, Object> m = getDoubleMap();
if (!m.containsKey(key)) {
m.put(key, new Object());
}
m.get(key).toString();
}
public void notWorking1(int key) {
Map<Integer, Object> m = getIntegerMap();
if (!m.containsKey(key)) {
m.put(key, new Object());
}
m.get(key).toString(); // Should not generate error but does
}
public void notWorking2(double key) {
Map<Double, Object> m = getDoubleMap();
if (!m.containsKey(key)) {
m.put(key, new Object());
}
m.get(key).toString(); // Should not generate error but does
}
public abstract Map<Object, Object> getObjectMap();
public abstract Map<Integer, Object> getIntegerMap();
public abstract Map<Double, Object> getDoubleMap();
}
When Map#get is invoked with an object argument, the key variable is correctly refined to be of the @KeyFor type. However, invoking the same method with a primitive type does not appear to perform the same refinement.
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.
Assessment
This issue has not been assessed yet.