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
WarnOnGenericInferenceFailure reports an inference failure for a @Nullable argument passed to a generic method of @NullUnmarked code #2125
With JSpecifyExperimental, passing a @Nullable argument to a generic method of unmarked code, with the result flowing into a @NonNull location (a return, a field, or a method argument), reports an inference failure. Unmarked code is otherwise treated optimistically: it accepts null, and its return values are assumed to be non-null. A real-world example is Refaster.emitCommentBefore("REPLACEME", null) (Error Prone, <T> T emitCommentBefore(String, T)), whose result is passed to a @NullMarked method.
Repro2.java:15: warning: [NullAway] inference failure: type variable T constrained to be both @NonNull and @Nullable
return Lib.id(s);
^
Reproduced with NullAway 0.14.3 and with master (002c08d), Error Prone 2.51.0, JDK 25. No diagnostic is reported with -XepOpt:NullAway:WarnOnGenericInferenceFailure=false.
Observations:
The same failure is reported for fld = Lib.id(s); (a String field) and take(Lib.id(s)) (for static String take(String s)).
String result = Lib.id(s); is not reported, nor is later returning, passing or dereferencing result, nor is Lib.id(s).trim(). I presume this is because the assignment does not constrain the top-level type of a local variable (see ConstraintSolver#addSubtypeConstraint, localVariableType).
Nested types are still constrained for locals, so there the local is no workaround: with static <T> List<T> listOf(T t) added to Lib, List<String> result = Lib.listOf(s); is reported with the same message.
Passing null rather than a @Nullable variable behaves the same, as does a callee in a class outside of AnnotatedPackages rather than a @NullUnmarked one.
If Lib is @NullMarked, the call is reported with both this inference failure and the regular "passing @nullable parameter" error, which seems right. For unmarked code I'd expect no diagnostic, or perhaps that inference is not attempted at all; is the current behavior intended?
Activity