Skip to content

Conversation

@ppkarwasz
Copy link
Contributor

This change adds nullability annotations (JSpecify) 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 safely be passed null 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 behavioral change (minor version bump), but it might be considered a breaking change.

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.
@jeremylong
Copy link
Collaborator

@ppkarwasz this is likely one of the few types of dependencies I'm okay with for packageurl-java - just annotations, no code. Would you mind fixing the merge conflicts?

Comment on lines 288 to +291
* @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();
Copy link
Contributor Author

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…

Comment on lines +245 to +250
*
* @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();
Copy link
Contributor Author

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.

Copy link
Collaborator

@jeremylong jeremylong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jeremylong jeremylong merged commit 1307449 into package-url:master Mar 12, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants