biddyweb / checker-framework

Automatically exported from code.google.com/p/checker-framework
Other
0 stars 1 forks source link

Map key heuristics with constant fields #388

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
The nullness checker reports an incorrect error for the following code.

This would likely be resolved by the fix for Issue 221.

I tested with javac 1.8.0-jsr308-1.8.9.

===
import java.util.Map;

class MapKeyConstant {
  static class Holder {
    static final String KEY = "key";
  }

  public String getOrDefault(Map<String, String> map, String defaultValue) {
    if (map.containsKey(Holder.KEY)) {
      return map.get(Holder.KEY);
    } else {
      return defaultValue;
    }
  }
}
===

Test.java:10: error: [return.type.incompatible] incompatible types in return.
      return map.get(Holder.KEY);
                    ^
  found   : @Initialized @Nullable String
  required: @Initialized @NonNull String

Original issue reported on code.google.com by cus...@google.com on 5 Jan 2015 at 6:39

GoogleCodeExporter commented 9 years ago
Thank you for reporting this issue. Indeed, this will be resolved by the fix 
for Issue 221. I will update this issue as progress is made on issue 221.

Original comment by jtha...@cs.washington.edu on 21 Jan 2015 at 10:01

GoogleCodeExporter commented 9 years ago

Original comment by jtha...@cs.washington.edu on 8 Apr 2015 at 11:04

GoogleCodeExporter commented 9 years ago

Original comment by jtha...@cs.washington.edu on 18 Apr 2015 at 6:42