jspecify / jspecify-reference-checker

The reference implementation for the JSpecify nullness specification (and later, its other specifications as well)
https://jspecify.org
Apache License 2.0
26 stars 7 forks source link

main-eisop: When `class Foo<T>` is null-unmarked, usages of `T` should have unspecified nullness #163

Closed cpovirk closed 7 months ago

cpovirk commented 9 months ago

I actually don't know if that's the specific problem here (especially when I'm testing mostly against code that is @NullMarked), but it's a good possibility for at least 50 errors [edit: probably more like 90+?] that I'm seeing—mostly in https://github.com/google/auto, which uses some unannotated annotation-processor APIs.

import org.jspecify.annotations.NullMarked;

@NullMarked
class NullForUnspecVoid {
  void x(Value val, Visitor<Void> vis) {
    val.accept(vis, null);
  }
}

interface Value {
  <P> void accept(Visitor<P> visitor, P param);
}

interface Visitor<P> {}
$ ../checker-framework/checker/bin/javac -processorpath $HOME/.m2/repository/org/jspecify/jspecify/0.3.0/jspecify-0.3.0.jar:build/libs/jspecify-reference-checker-0.0.0-SNAPSHOT.jar -processor com.google.jspecify.nullness.NullSpecChecker -AcheckImpl -AassumePure -AsuppressWarnings=contracts.conditional.postcondition.false.methodref,contracts.conditional.postcondition.false.override,contracts.conditional.postcondition.true.methodref,contracts.conditional.postcondition.true.override,purity.methodref,purity.overriding,type.anno.before.decl.anno,type.anno.before.modifier -cp $HOME/.m2/repository/org/jspecify/jspecify/0.3.0/jspecify-0.3.0.jar:build/libs/jspecify-reference-checker-0.0.0-SNAPSHOT.jar NullForUnspecVoid.java
NullForUnspecVoid.java:6: error: [argument.type.incompatible] incompatible argument for parameter param of Value.accept.
    val.accept(vis, null);
                    ^
  found   : null?
  required: Void
1 error

I would expect the required type to be Void*, since Visitor isn't annotated for nullness.

This requires a way to apply defaults to type-variable usages, as discussed in https://github.com/jspecify/checker-framework/issues/7.

wmdietl commented 7 months ago

Fixed by #165.