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
The JSpecify nullness annotations will give developers better exposure to potential problems with their code to avoid NullPointerExceptions.
Related issue: #14291
Types of changes
Bug fix (non-breaking change which fixes an issue)
New feature (non-breaking change which adds functionality)
Breaking change (fix or feature that would cause existing functionality to change)
The generic type bounds using @nullable might affect type safety in existing code using the Either class. Need to verify this change doesn't break existing usage patterns.
Why: The suggestion adds crucial type validation before casting, preventing potential runtime ClassCastExceptions that could occur if the map contains values of unexpected types. This is a significant safety improvement.
8
Handle invalid enum values explicitly
Add a default case to handle invalid values in the getEnum method to avoid returning null silently. Consider throwing an IllegalArgumentException for invalid inputs.
public static @Nullable AppCacheStatus getEnum(int value) {
for (AppCacheStatus status : AppCacheStatus.values()) {
if (value == status.value()) {
return status;
}
}
- return null;+ throw new IllegalArgumentException("Invalid AppCacheStatus value: " + value);
}
Apply this suggestion
Suggestion importance[1-10]: 7
Why: The suggestion improves error handling by making invalid enum values fail fast with a clear error message instead of silently returning null, which could lead to NullPointerException issues later.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
User description
Description
Changed files
org.openqa.selenium.html5.AppCacheStatus- nullable annotations addedorg.openqa.selenium.internal.Either- nullable annotations added (docs: Declaring generic types)org.openqa.selenium.virtualauthenticator.Credential- added null value checking to avoid unexpected NPEsNullAway analysis: #14421
Motivation and Context
The JSpecify nullness annotations will give developers better exposure to potential problems with their code to avoid NullPointerExceptions.
Related issue: #14291
Types of changes
Checklist
PR Type
Enhancement, Bug fix
Description
Added JSpecify nullness annotations to improve null safety.
AppCacheStatusenum with@NullMarkedand@Nullable.Eitherclass with nullness annotations for generic types.Improved null value handling in
Credential.fromMapmethod.Changes walkthrough 📝
AppCacheStatus.java
Add nullness annotations to AppCacheStatusjava/src/org/openqa/selenium/html5/AppCacheStatus.java
@NullMarkedannotation to the class.getEnummethods with@Nullablefor null safety.Either.java
Add nullness annotations to Either classjava/src/org/openqa/selenium/internal/Either.java
@NullMarkedannotation to the class.@Nullableto indicate nullability.Credential.java
Improve null handling in Credential.fromMapjava/src/org/openqa/selenium/virtualauthenticator/Credential.java
fromMapmethod.