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
Handle @NullUnmarked methods with explicit @NonNull annotations in JDK javac plugin #1498
The JSON from the javac plugin already carries method-level @NullUnmarked (NullnessAnnotationSerializer passes hasNullUnmarked into MethodInfo), but AstubxGenerator.getMethodRecords ignores it and writes only Nullable annotations. The astubx record and the stubx reader in LibraryModelsHandler already accept an explicit NonNull on a parameter, but the record has no slot for "unmarked". So with JSpecifyJDKModels on, an @NullUnmarked method in a @NullMarked JDK class is checked as fully null-marked.
This is visible to users as false positives on the @NullUnmarked methods of jspecify/jdk whose parameters carry no annotation: HttpCookie(String, String), HttpCookie.setValue, MulticastSocket.setInterface, and MulticastSocket.setNetworkInterface (also the protected KeyStore constructor). The same source compiles cleanly with JSpecifyJDKModels=false. Files.getAttribute(p, null) is reported today only because the whole method is treated as marked; after the fix it should still be reported, since its parameters are explicitly @NonNull.
Flags: -XepOpt:NullAway:AnnotatedPackages=foo-XepOpt:NullAway:JSpecifyMode=true-XDaddTypeAnnotationsToSymbol=true-XepOpt:NullAway:JSpecifyExperimental=true (turns on JSpecifyJDKModels)
packagefoo;
importjava.net.HttpCookie;
importjava.net.MulticastSocket;
importjava.nio.file.Files;
importjava.nio.file.Path;
importorg.jspecify.annotations.NullMarked;
@NullMarkedclassTest {
voidcookie(HttpCookiec) {
c.setValue(null); // reported, should not be: setValue is @NullUnmarked
}
HttpCookiector() {
returnnewHttpCookie("n", null); // reported, should not be
}
voidsocket(MulticastSockets) throwsException {
s.setInterface(null); // reported, should not be
}
Objectattr(Pathp) throwsException {
returnFiles.getAttribute(p, null); // reported, and should stay reported: explicit @NonNull
}
}
Observed: passing @Nullable parameter 'null' where @NonNull is required on the setValue, HttpCookie constructor, setInterface, and getAttribute lines. Expected: only the getAttribute line is reported. With -XepOpt:NullAway:JSpecifyJDKModels=false none of the first three is reported.
Activity
vlsi commentedon Oct 22, 2026
The JSON from the javac plugin already carries method-level
@NullUnmarked(NullnessAnnotationSerializerpasseshasNullUnmarkedintoMethodInfo), butAstubxGenerator.getMethodRecordsignores it and writes onlyNullableannotations. The astubx record and the stubx reader inLibraryModelsHandleralready accept an explicitNonNullon a parameter, but the record has no slot for "unmarked". So withJSpecifyJDKModelson, an@NullUnmarkedmethod in a@NullMarkedJDK class is checked as fully null-marked.This is visible to users as false positives on the
@NullUnmarkedmethods ofjspecify/jdkwhose parameters carry no annotation:HttpCookie(String, String),HttpCookie.setValue,MulticastSocket.setInterface, andMulticastSocket.setNetworkInterface(also the protectedKeyStoreconstructor). The same source compiles cleanly withJSpecifyJDKModels=false.Files.getAttribute(p, null)is reported today only because the whole method is treated as marked; after the fix it should still be reported, since its parameters are explicitly@NonNull.Reproducer (NullAway 3035507, JDK 21)
Flags:
-XepOpt:NullAway:AnnotatedPackages=foo-XepOpt:NullAway:JSpecifyMode=true-XDaddTypeAnnotationsToSymbol=true-XepOpt:NullAway:JSpecifyExperimental=true(turns onJSpecifyJDKModels)Observed:
passing @Nullable parameter 'null' where @NonNull is requiredon thesetValue,HttpCookieconstructor,setInterface, andgetAttributelines. Expected: only thegetAttributeline is reported. With-XepOpt:NullAway:JSpecifyJDKModels=falsenone of the first three is reported.