Repository navigation
Description
Version
NullAway 0.14.0, and current master (21f02dd). Error Prone 2.50.0, JDK 21.
Flags: -XepOpt:NullAway:JSpecifyMode=true -XepOpt:NullAway:JSpecifyJDKModels=true -XDaddTypeAnnotationsToSymbol=true.
Summary
A Collection<?> parameter declared in a @NullMarked class read from bytecode rejects an argument of type Collection<@Nullable String>. The same Collection<?> written in annotated source accepts it.
incompatible types: Collection<@Nullable String> cannot be converted to Collection<?>
An unbounded wildcard should accept any type argument, and it does everywhere except in a signature that came from bytecode.
Reproducer
package foo;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;
@NullMarked
class Test {
static boolean containsAll(List<String> l, Collection<@Nullable String> o) {
// BUG: Diagnostic contains: incompatible types: Collection<@Nullable String> cannot be converted to Collection<?>
return l.containsAll(o);
}
// a JDK static method with the same parameter shape and no receiver: both arguments report
static boolean disjoint(Collection<@Nullable String> a, Collection<@Nullable String> b) {
// BUG: Diagnostic contains: incompatible types: Collection<@Nullable String> cannot be converted to Collection<?>
return Collections.disjoint(a, b);
}
// the same parameter type, declared in source: clean
static boolean ownStatic(Collection<?> c) {
return c.isEmpty();
}
static boolean callOwnStatic(Collection<@Nullable String> o) {
return ownStatic(o);
}
// assignment to a source-declared Collection<?>: clean
static Collection<?> assign(Collection<@Nullable String> o) {
return o;
}
}removeAll and retainAll behave like containsAll.
What does and does not report
| Call | Reported |
|---|---|
list.containsAll(Collection<@Nullable String>) |
yes |
list.removeAll(Set<@Nullable String>) |
yes |
list.retainAll(Collection<@Nullable String>) |
yes |
Collections.disjoint(Collection<@Nullable String>, ...) — static, no receiver |
yes |
list.contains(@Nullable String) — single-element form |
no |
list.removeAll(Collection<String>) — non-null argument elements |
no |
source-declared f(Collection<?>) called with Collection<@Nullable String> |
no |
source-declared f(Collection<? extends @Nullable Object>) |
no |
Collection<?> c = someCollectionOfNullable; |
no |
The receiver's element type does not matter: List<@Nullable String>.removeAll(Collection<@Nullable String>) reports, and List<@Nullable String>.removeAll(Collection<String>) does not. Only the argument's element type decides, and Collections.disjoint shows that no receiver need be involved at all.
What appears to be going on
jspecify-jdk.astubx carries no method entry for containsAll, removeAll, retainAll, or contains on Collection, List, or Set. Dumping the parsed model, what it does record for java.util.Collection is that the class is @NullMarked and that its type parameter E has a @Nullable upper bound.
So the parameter type is read from the bytecode signature, and the unbounded ? in it ends up behaving like ? extends Object with a non-null bound rather than an unbounded wildcard. Writing the identical signature in source gives the correct behavior, which is what makes the two paths disagree.
This looks adjacent to #1717, which recently fixed restoring nullness annotations from an unbounded wildcard to the captured type.
Expected
Collection<@Nullable String> is a Collection<?>. A signature read from bytecode should treat an unbounded wildcard the same way a signature read from source does.
Workaround
@SuppressWarnings("NullAway") on the calling method.
Where we hit it
SqlNodeList delegates all three bulk methods to a List<@Nullable SqlNode>, and SubstitutionVisitor removes a set of parents of which the root's is null. Found while replacing the Checker Framework with NullAway in Apache Calcite (apache/calcite#5213).
Activity
[CALCITE-7736] Say where a value is genuinely absent, and work around…
[CALCITE-7736] Put :geode under nullness verification
[CALCITE-7736] Say where a value is genuinely absent, and work around…
[CALCITE-7736] Put :geode under nullness verification
[CALCITE-7736] Say where a value is genuinely absent, and work around…
[CALCITE-7736] Put :geode under nullness verification
[CALCITE-7736] Say where a value is genuinely absent, and work around…
[CALCITE-7736] Put :geode under nullness verification
retrodaredevil commentedon Aug 26, 2026
I'm facing the same issue. Here's two ways I reproduced it:
or without Reactor Core APIs:
msridhar commentedon Aug 27, 2026
Still working on this one, but as an FYI, I think this is fixed if you compile using JDK 25. Working on a JDK 17/21 fix.
vlsi commentedon Aug 28, 2026
You are right, one should use the latest compiler. Don't spend to much time on adding workarounds for older compilers.
For now, Calcite uses "current JAVA_HOME" for compilation which to me is just wrong. It should always use JDK 25 for javac and target the release via
--release.msridhar commentedon Aug 28, 2026
Well, we do officially support JDK 17 and 21 (with
-XDaddTypeAnnotationsToSymbol=true). So we should fix this one.Agreed! Or even JDK 26.
javacgets some bug fixes and improvements in every version, and--releaseworks well in most cases.vlsi commentedon Aug 28, 2026
AFAIK JDK 26 does not support
--release 8while Calcite and pgjdbc officially support Java 8 :)msridhar commentedon Aug 28, 2026
Looks like it's supported but causes warnings:
24 remaining items
[CALCITE-7736] Put :geode under nullness verification
[CALCITE-7736] Say where a value is genuinely absent, and work around…
[CALCITE-7736] Put :geode under nullness verification
[CALCITE-7736] Say where a value is genuinely absent, and work around…
[CALCITE-7736] Close out the last of the core findings
[CALCITE-7736] Put :geode under nullness verification
[CALCITE-7736] Put :geode under nullness verification
[CALCITE-7736] Put :geode under nullness verification
[CALCITE-7736] Put :geode under nullness verification
[CALCITE-7736] Put :geode under nullness verification
[CALCITE-7736] Put :geode under nullness verification
[CALCITE-7736] Put :geode under nullness verification
[CALCITE-7736] Put :geode under nullness verification
[CALCITE-7736] Put :geode under nullness verification
[CALCITE-7736] Put :geode under nullness verification