Skip to content

Commit 5a66cf9

Browse files
mk868pujagani
andauthored
[java] Add nullness for AppCacheStatus, Credential, and Either (#15119)
Co-authored-by: Puja Jagani <[email protected]>
1 parent 5481538 commit 5a66cf9

File tree

3 files changed

+25
-11
lines changed

3 files changed

+25
-11
lines changed

Diff for: java/src/org/openqa/selenium/html5/AppCacheStatus.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,12 @@
1717

1818
package org.openqa.selenium.html5;
1919

20+
import org.jspecify.annotations.NullMarked;
21+
import org.jspecify.annotations.Nullable;
22+
2023
/** Represents the application cache status. */
2124
@Deprecated
25+
@NullMarked
2226
public enum AppCacheStatus {
2327
UNCACHED(0),
2428
IDLE(1),
@@ -43,7 +47,7 @@ public int value() {
4347
* @param value The input value
4448
* @return {@link AppCacheStatus} The corresponding appcache status
4549
*/
46-
public static AppCacheStatus getEnum(int value) {
50+
public static @Nullable AppCacheStatus getEnum(int value) {
4751
for (AppCacheStatus status : AppCacheStatus.values()) {
4852
if (value == status.value()) {
4953
return status;
@@ -52,7 +56,7 @@ public static AppCacheStatus getEnum(int value) {
5256
return null;
5357
}
5458

55-
public static AppCacheStatus getEnum(String value) {
59+
public static @Nullable AppCacheStatus getEnum(String value) {
5660
for (AppCacheStatus status : AppCacheStatus.values()) {
5761
if (status.toString().equalsIgnoreCase(value)) {
5862
return status;

Diff for: java/src/org/openqa/selenium/internal/Either.java

+6-3
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,11 @@
2121
import java.util.Iterator;
2222
import java.util.function.Function;
2323
import java.util.stream.Stream;
24+
import org.jspecify.annotations.NullMarked;
25+
import org.jspecify.annotations.Nullable;
2426

25-
public class Either<A, B> implements Iterable<B> {
27+
@NullMarked
28+
public class Either<A extends @Nullable Object, B extends @Nullable Object> implements Iterable<B> {
2629
private final A left;
2730
private final B right;
2831

@@ -31,11 +34,11 @@ private Either(A a, B b) {
3134
right = b;
3235
}
3336

34-
public static <A, B> Either<A, B> left(A a) {
37+
public static <A extends @Nullable Object, B extends @Nullable Object> Either<A, B> left(A a) {
3538
return new Either<>(a, null);
3639
}
3740

38-
public static <A, B> Either<A, B> right(B b) {
41+
public static <A extends @Nullable Object, B extends @Nullable Object> Either<A, B> right(B b) {
3942
return new Either<>(null, b);
4043
}
4144

Diff for: java/src/org/openqa/selenium/virtualauthenticator/Credential.java

+13-6
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,21 @@ public static Credential createResidentCredential(
6363

6464
/** Creates a credential from a map. */
6565
public static Credential fromMap(Map<String, Object> map) {
66+
Object credentialId = Require.nonNull("credentialId", map.get("credentialId"));
67+
Object isResidentCredential =
68+
Require.nonNull("isResidentCredential", map.get("isResidentCredential"));
69+
Object rpId = Require.nonNull("rpId", map.get("rpId"));
70+
Object privateKey = Require.nonNull("privateKey", map.get("privateKey"));
71+
Object userHandle = map.get("userHandle");
72+
Object signCount = Require.nonNull("signCount", map.get("signCount"));
6673
Base64.Decoder decoder = Base64.getUrlDecoder();
6774
return new Credential(
68-
decoder.decode((String) map.get("credentialId")),
69-
(boolean) map.get("isResidentCredential"),
70-
(String) map.get("rpId"),
71-
new PKCS8EncodedKeySpec(decoder.decode((String) map.get("privateKey"))),
72-
map.get("userHandle") == null ? null : decoder.decode((String) map.get("userHandle")),
73-
((Long) map.get("signCount")).intValue());
75+
decoder.decode((String) credentialId),
76+
(boolean) isResidentCredential,
77+
(String) rpId,
78+
new PKCS8EncodedKeySpec(decoder.decode((String) privateKey)),
79+
userHandle == null ? null : decoder.decode((String) userHandle),
80+
((Long) signCount).intValue());
7481
}
7582

7683
private Credential(

0 commit comments

Comments
 (0)