typetools / typetools/checker-framework

<?> in a stub doesn't override <? extends @NonNull Object> in a source. collection-object-parameters-may-be-null.astub is affected.

Open
#3,236 4 comments 0 reactions 1 assignee View on GitHub

@smillst is already working on this.

Since May 28, 2020.

Dominant language
Java
Stars
1.1k
Forks
440
Avg merge
1d 12h
Merged PRs (30d)
134

Description

$ cat ContainsAllRetainAll.java 
import java.util.Collection;

class ContainsAllRetainAll {
  void bulkOperations(Collection<?> a, Collection<?> b) {
    a.containsAll(b);
    a.retainAll(b);
  }
}

I would expect for this to fail with the new JDK stubs in 3.3.0 (and it does). However, I would expect it to pass when I supply -Astubs=collection-object-parameters-may-be-null.astub, yet it still fails:

$ checker/bin/javac -processor org.checkerframework.checker.nullness.NullnessChecker -Astubs=collection-object-parameters-may-be-null.astub ContainsAllRetainAll.java
warning: StubParser: annotateTypeParameters: mismatched sizes:  typeParameters (size 0)=[];  typeArguments (size 1)=[E extends Object];  decl=class AbstractCollection {      @Pure     public boolean contains(@Nullable Object o);      public boolean remove(@Nullable Object o);      @Pure     public boolean containsAll(Collection<?> c);      public boolean removeAll(Collection<?> c);      public boolean retainAll(Collection<?> c); };  elt=java.util.AbstractCollection (class com.sun.tools.javac.code.Symbol$ClassSymbol).; for more details, run with -AstubDebug
warning: StubParser: annotateTypeParameters: mismatched sizes:  typeParameters (size 0)=[];  typeArguments (size 2)=[K extends Object, V extends Object];  decl=class AbstractMap {      public boolean containsValue(@Nullable Object value);      public boolean containsKey(@Nullable Object key);      @Nullable     public V get(@Nullable Object key);      @Nullable     public V remove(@Nullable Object key); };  elt=java.util.AbstractMap (class com.sun.tools.javac.code.Symbol$ClassSymbol).; for more details, run with -AstubDebug
warning: StubParser: annotateTypeParameters: mismatched sizes:  typeParameters (size 0)=[];  typeArguments (size 1)=[E extends Object];  decl=class AbstractSet {      public boolean removeAll(Collection<?> c); };  elt=java.util.AbstractSet (class com.sun.tools.javac.code.Symbol$ClassSymbol).; for more details, run with -AstubDebug
warning: StubParser: annotateTypeParameters: mismatched sizes:  typeParameters (size 0)=[];  typeArguments (size 1)=[E extends Object];  decl=class Vector {      public synchronized boolean containsAll(Collection<?> c);      public synchronized boolean removeAll(Collection<?> c);      public synchronized boolean retainAll(Collection<?> c); };  elt=java.util.Vector (class com.sun.tools.javac.code.Symbol$ClassSymbol).; for more details, run with -AstubDebug
warning: StubParser: stub file does not match bytecode: could not find superinterface List<E> from type CopyOnWriteArraySet<E extends Object>
warning: StubParser: stub file does not match bytecode: could not find superinterface RandomAccess from type CopyOnWriteArraySet<E extends Object>
warning: StubParser: stub file does not match bytecode: could not find superinterface Cloneable from type CopyOnWriteArraySet<E extends Object>
warning: StubParser: annotateTypeParameters: mismatched sizes:  typeParameters (size 0)=[];  typeArguments (size 1)=[E extends @Initialized @Nullable Object];  decl=class AbstractCollection {      @Pure     public boolean contains(@Nullable Object o);      public boolean remove(@Nullable Object o);      @Pure     public boolean containsAll(Collection<?> c);      public boolean removeAll(Collection<?> c);      public boolean retainAll(Collection<?> c); };  elt=java.util.AbstractCollection (class com.sun.tools.javac.code.Symbol$ClassSymbol).; for more details, run with -AstubDebug
warning: StubParser: annotateTypeParameters: mismatched sizes:  typeParameters (size 0)=[];  typeArguments (size 2)=[K extends @Initialized @Nullable Object, V extends @Initialized @Nullable Object];  decl=class AbstractMap {      public boolean containsValue(@Nullable Object value);      public boolean containsKey(@Nullable Object key);      @Nullable     public V get(@Nullable Object key);      @Nullable     public V remove(@Nullable Object key); };  elt=java.util.AbstractMap (class com.sun.tools.javac.code.Symbol$ClassSymbol).; for more details, run with -AstubDebug
warning: StubParser: annotateTypeParameters: mismatched sizes:  typeParameters (size 0)=[];  typeArguments (size 1)=[E extends @Initialized @Nullable Object];  decl=class AbstractSet {      public boolean removeAll(Collection<?> c); };  elt=java.util.AbstractSet (class com.sun.tools.javac.code.Symbol$ClassSymbol).; for more details, run with -AstubDebug
warning: StubParser: annotateTypeParameters: mismatched sizes:  typeParameters (size 0)=[];  typeArguments (size 1)=[E extends @Initialized @Nullable Object];  decl=class Vector {      public synchronized boolean containsAll(Collection<?> c);      public synchronized boolean removeAll(Collection<?> c);      public synchronized boolean retainAll(Collection<?> c); };  elt=java.util.Vector (class com.sun.tools.javac.code.Symbol$ClassSymbol).; for more details, run with -AstubDebug
warning: StubParser: stub file does not match bytecode: could not find superinterface List<E> from type CopyOnWriteArraySet<E extends @Initialized @Nullable Object>
warning: StubParser: stub file does not match bytecode: could not find superinterface RandomAccess from type CopyOnWriteArraySet<E extends @Initialized @Nullable Object>
warning: StubParser: stub file does not match bytecode: could not find superinterface Cloneable from type CopyOnWriteArraySet<E extends @Initialized @Nullable Object>
ContainsAllRetainAll.java:5: error: [argument.type.incompatible] incompatible types in argument.
    a.containsAll(b);
                  ^
  found   : @Initialized @NonNull Collection<? extends @Initialized @Nullable Object>
  required: @Initialized @NonNull Collection<? extends @Initialized @NonNull Object>
ContainsAllRetainAll.java:6: error: [argument.type.incompatible] incompatible types in argument.
    a.retainAll(b);
                ^
  found   : @Initialized @NonNull Collection<? extends @Initialized @Nullable Object>
  required: @Initialized @NonNull Collection<? extends @Initialized @NonNull Object>
2 errors
14 warnings

I have gotten myself a little confused as I investigate: I thought I later even went and rebuilt CF's built-in annotated JDK stubs with the parameter types changed to Collection<? extends @Nullable Object> and still saw the error (with or without the astub file). But I wouldn't rule out the possibility that I messed something up during that. I think I at least have the original report correct :)

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.