From 53f17251469e56d025837f78ed2cbcab7090e11e Mon Sep 17 00:00:00 2001 From: Chris Povirk Date: Thu, 21 Nov 2024 15:32:10 -0500 Subject: [PATCH] Give the `Provider` constructor parameter of `KeyStore` unspecified nullness. As discussed in https://github.com/jspecify/jdk/pull/29#issuecomment-1653637366, I can't tell whether it should be `@Nullable` or not. The way to give it unspecified nullness is to use `@NullUnmarked`. To at least keep non-null types for the _other_ two parameters, I've added `@NonNull` on them. This would be slightly simpler with [a type-use annotation for unspecified nullness](https://github.com/jspecify/jspecify/issues/137). But the approach described above works fine (if somewhat verbosely), since there this API doesn't use parametric nullness. --- src/java.base/share/classes/java/security/KeyStore.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/java.base/share/classes/java/security/KeyStore.java b/src/java.base/share/classes/java/security/KeyStore.java index 5b9bfe8d06c..9ac02b51b82 100644 --- a/src/java.base/share/classes/java/security/KeyStore.java +++ b/src/java.base/share/classes/java/security/KeyStore.java @@ -25,7 +25,9 @@ package java.security; +import org.jspecify.annotations.NonNull; import org.jspecify.annotations.NullMarked; +import org.jspecify.annotations.NullUnmarked; import org.jspecify.annotations.Nullable; import java.io.*; @@ -814,7 +816,8 @@ public String toString() { * @param provider the provider. * @param type the keystore type. */ - protected KeyStore(KeyStoreSpi keyStoreSpi, Provider provider, String type) + @NullUnmarked // https://github.com/jspecify/jdk/pull/29#issuecomment-1653637366 + protected KeyStore(@NonNull KeyStoreSpi keyStoreSpi, Provider provider, @NonNull String type) { this.keyStoreSpi = keyStoreSpi; this.provider = provider;