You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
JSpecify: a wildcard type argument of an unannotated generic type is rejected in @NullMarked code #1778
In @NullMarked code, reading a generic member off a wildcard-typed value fails when the generic type itself is unannotated. The type variable of the unannotated type gets a @Nullable Object upper bound, and the wildcard then no longer converts to the wildcard of an annotated type.
This is the shape left over from #1732. #1764 fixed the annotated cases there, such as Collection<?>.removeAll, and this one still reports.
Reproducer
// No @NullMarked on this file, its package, or its module.packageexample.unannotated;
publicinterfaceBox<V> {
Class<V> valueType();
}
Use.java:8: warning: [NullAway] incompatible types: Class<capture of ?> cannot be converted to Class<?> (target wildcard upper bound is Object; source wildcard upper bound is @Nullable Object; source wildcard is the type argument for type variable V of Box)
Box is unannotated, so I expect its V to carry unspecified nullness and the read to pass. Two changes silence it: annotating Box with @NullMarked, or naming the type argument as Box<String>. In annotated code that leaves a raw type or a suppression as the only ways out.
Where it comes from
Apache Calcite reads region.getAttributes().getValueConstraint() off Apache Geode's Region<?, ?>, and geode-core ships unannotated bytecode. The workaround today is a raw Class plus @SuppressWarnings("rawtypes"): GeodeUtils.autodetectRelTypeFromRegion.
Versions
Reproduces on 0.14.0 and on main at 915b287. Error Prone 2.50.0, JSpecify 1.0.1, JDK 21, with JSpecifyMode, JSpecifyExperimental, HandleWildcardGenerics, JSpecifyJDKModels, and OnlyNullMarked all enabled.
One case I assume is intended
ImmutableMap.copyOf(map) on a Map<String, ?> reports inference failure: type variable V is constrained to be @Nullable, but its upper bound requires it to be @NonNull, because Map's V has a @Nullable Object bound while Guava's ImmutableMap requires a non-null one. A Map<String, ?> can hold nulls and copyOf would throw on them, so I read that one as a true positive. Say so if it is not, and I will file it separately.
For the capture of this wildcard, that bound gets combined with the Object UNSPECIFIED upper bound of V, yielding @Nullable Object as its upper bound. But, in the JSpecify JDK model, the T type variable of Class has a @NonNull upper bound:
Agreed. The raw Class was hiding a real incompatibility rather than working around a defect, and the same reading explains the Guava case I put at the bottom of the report.
Region<? extends Object, ? extends Object> works, and on 0.14.0, so nothing here waits on a release. Both sites are clean with the raw type and both suppressions gone: GeodeUtils.autodetectRelTypeFromRegion and DataContexts, where the bound also moves up to the public DataContexts.of factory. It is the same Java type either way, so callers compile unchanged.
Activity
msridhar commentedon Aug 29, 2026
I think this error is valid. The key is that in null-marked code, an unbounded wildcard has an implicit upper bound of
@Nullable Object:https://jspecify.dev/docs/spec/#unbounded-wildcard
For the capture of this wildcard, that bound gets combined with the
Object UNSPECIFIEDupper bound ofV, yielding@Nullable Objectas its upper bound. But, in the JSpecify JDK model, theTtype variable ofClasshas a@NonNullupper bound:https://github.com/jspecify/jdk/blob/397fbb20a940e9ae679b268358e6f74396a8938c/src/java.base/share/classes/java/lang/Class.java#L218-L220
So we have an incompatibility.
@vlsi do you agree?
msridhar commentedon Aug 29, 2026
For your original code, can you write
Region<? extends Object, ? extends Object> regionas a workaround?vlsi commentedon Aug 29, 2026
Agreed. The raw
Classwas hiding a real incompatibility rather than working around a defect, and the same reading explains the Guava case I put at the bottom of the report.Region<? extends Object, ? extends Object>works, and on 0.14.0, so nothing here waits on a release. Both sites are clean with the raw type and both suppressions gone: GeodeUtils.autodetectRelTypeFromRegion and DataContexts, where the bound also moves up to the publicDataContexts.offactory. It is the same Java type either way, so callers compile unchanged.Please close this one. Thanks for the quick read.