kelloggm / checkerframework-gradle-plugin

Gradle plugin to use the Checker Framework for Java
Apache License 2.0
64 stars 15 forks source link

HashMap::put doesn't accept a nullable value #134

Closed xenoterracide closed 3 years ago

xenoterracide commented 3 years ago
          var argMap = new HashMap<String, Object>();
          argMap.put( "language", language );
          argMap.put( "moduleType", moduleType );
          argMap.put( "project", project );
          argMap.put( "name", name ); // name is Nullable
/Users/calebcushing/IdeaProjects/brix/src/main/java/com/xenoterracide/brix/Application.java:116: error: [argument.type.incompatible] incompatible argument for parameter arg1 of put.
          argMap.put( "name", name );
                              ^
  found   : @Initialized @Nullable String
  required: @Initialized @NonNull Object

I think it should be this, since the documentation for HashMap clearly states it can have null keys or values.

package java.util;

import org.checkerframework.checker.nullness.qual.PolyNull;
import org.checkerframework.checker.nullness.qual.Nullable;

public class HashMap<K,V> extends AbstractMap<K,V>
    implements Map<K,V>, Cloneable, Serializable {

    @PolyNull V put( @Nullable K key, @PolyNull V value);
}
xenoterracide commented 3 years ago

oops this was supposed to be in checker-framework