Skip to content

Replace nullness annotations with JSpecify#309

Merged
piotrooo merged 2 commits intosemver4j:mainfrom
mk868:jspecify
Dec 18, 2024
Merged

Replace nullness annotations with JSpecify#309
piotrooo merged 2 commits intosemver4j:mainfrom
mk868:jspecify

Conversation

@mk868
Copy link
Copy Markdown
Contributor

@mk868 mk868 commented Nov 25, 2024

Replace nullness annotations with JSpecify.
Related issue #308

Changes in this PR:

  • pom.xml: org.jetbrains:annotations replaced with org.jspecify:jspecify (docs)
  • Replace @NonNull annotations with @NullMarked annotation - to mark all types in the class scope as non-null by default (docs)
  • Move @Nullable annotations to types
    • @Nullable public static Semver -> public static @Nullable Semver
    • @Nullable final String version -> final @Nullable String version
  • Removed single use of the org.jetbrains.annotations.ApiStatus.AvailableSince annotation - we have same info in the JavaDoc @since tag
  • Fixed invalid annotation in the src/test/java/org/semver4j/internal/range/processor/ProcessorTest.java file (when we implement an interface, we should keep the same type annotations)

@piotrooo piotrooo added the enhancement New feature or request label Nov 25, 2024
@mk868
Copy link
Copy Markdown
Contributor Author

mk868 commented Dec 13, 2024

If necessary, I can split this PR into smaller parts, for example PR per package, it may be easier to track changes

Copy link
Copy Markdown
Member

@piotrooo piotrooo left a comment

Choose a reason for hiding this comment

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

Firstly, thanks for your work!
Secondly, sorry for the late response 😭

Regarding the code - one thing: for the return method, I prefer placing the annotation at the method level rather that next to the return type.

This is described in the Google Java Style Guide.

Use:

@Nullable
public static String coerce(@NotNull final String version)

Instead:

public static @Nullable String coerce(final String version)

@mk868
Copy link
Copy Markdown
Contributor Author

mk868 commented Dec 17, 2024

Sure - javac will generate exactly the same byte code for @Nullable public static String coerce(...) and public static @Nullable String coerce(...).
I'll push changes soon

Worth to mention: JSpecify's @Nullable and @NonNull are TYPE_USE annotations - and Google Style describes how to use them, but in this case it really doesn't matter

@mk868 mk868 requested a review from piotrooo December 18, 2024 20:19
@mk868
Copy link
Copy Markdown
Contributor Author

mk868 commented Dec 18, 2024

Okay, I moved the @Nullable annotations before the methods, as requested

@piotrooo piotrooo merged commit c4e7e20 into semver4j:main Dec 18, 2024
@mk868 mk868 deleted the jspecify branch December 19, 2024 09:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants