-
Notifications
You must be signed in to change notification settings - Fork 19
Add JSpecify nullability annotations #175
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This change adds nullability annotations ([JSpecify](https://jspecify.dev)) to `packageurl-java` and modifies somes behavior. Specifically: - It marks with `@Nullable` all public methods that can return `null`. - It marks with `@Nullable` all method parameters that can have a `null` value **without** throwing any exception. - It modifies the behavior of the remaining parameters: passing `null` to those parameters will result in an NPE, instead of `MalformedPackageURLException`. This is at least a behavior change (minor version bump), but it _might_ be a breaking change.
|
@ppkarwasz this is likely one of the few types of dependencies I'm okay with for |
| * @return all qualifiers set in this builder, or an empty map if none are set | ||
| */ | ||
| public Map<String, String> getQualifiers() { | ||
| if (qualifiers == null) { | ||
| return null; | ||
| } | ||
| return Collections.unmodifiableMap(qualifiers); | ||
| return qualifiers != null ? Collections.unmodifiableMap(qualifiers) : Collections.emptyMap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current Javadoc suggests that this method returns an empty map instead of null, so I changed the implementation…
| * | ||
| * @return all the qualifiers, or an empty map if none are set | ||
| * @since 1.0.0 | ||
| */ | ||
| public Map<String, String> getQualifiers() { | ||
| return (qualifiers != null) ? Collections.unmodifiableMap(qualifiers) : null; | ||
| return qualifiers != null ? Collections.unmodifiableMap(qualifiers) : Collections.emptyMap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since one of the tests checks if all PackageURL getters return the same as the PackageURLBuilder getters, I introduced a behavioral change here too.
jeremylong
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This change adds nullability annotations (JSpecify) to
packageurl-javaand modifies somes behavior. Specifically:@Nullableall public methods that can returnnull.@Nullableall method parameters that can safely be passednullwithout throwing any exception.nullto those parameters will result in an NPE, instead ofMalformedPackageURLException. This is at least a behavioral change (minor version bump), but it might be considered a breaking change.