typetools / typetools/checker-framework

@KeyFor refinement doesn't work for autoboxed types

Open
#595 2 comments 0 reactions 1 assignee View on GitHub

@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

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.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.