Skip to content

Pull #2290: Modernize codebase with Java improvements - Replace custom null checks with Objects.requireNonNull #2290

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Pankraz76
Copy link
Contributor

@Pankraz76 Pankraz76 commented May 2, 2025

@Pankraz76 Pankraz76 marked this pull request as ready for review May 2, 2025 18:42
@Pankraz76 Pankraz76 changed the title Pull #2287: Modernize codebase with Java improvements - Replace custom null checks with Objects.requireNonNull Pull #2290: Modernize codebase with Java improvements - Replace custom null checks with Objects.requireNonNull May 2, 2025
Pankraz76 pushed a commit to Pankraz76/maven that referenced this pull request May 2, 2025
… custom null checks with Objects.requireNonNull
@mthmulders mthmulders changed the title Pull #2290: Modernize codebase with Java improvements - Replace custom null checks with Objects.requireNonNull Pull #2290: Modernize codebase with Java improvements - Replace custom null checks with Objects.requireNonNull May 6, 2025
Pankraz76 pushed a commit to Pankraz76/maven that referenced this pull request May 6, 2025
… custom null checks with Objects.requireNonNull
@Pankraz76 Pankraz76 requested a review from olamy May 6, 2025 14:42
… custom null checks with Objects.requireNonNull

@Named
@Singleton
public class DefaultArtifactCoordinatesFactory implements ArtifactCoordinatesFactory {
@Override
public ArtifactCoordinates create(@Nonnull ArtifactCoordinatesFactoryRequest request) {
nonNull(request, "request");
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this pattern is re-ocurring a lot for defensive programming. Actually the outcome is quite the same, resulting in NPE. With the only benefit of giving NullPointerException("request") instead of raw NullPointerException().

High invasive on code for little change. Why not giving dedicated abstraction layer for this? Reducing overhead to minimum, getting the message spec for free:

image

https://projectlombok.org/features/NonNull

@@ -134,7 +134,7 @@ public AbstractSession(
List<RemoteRepository> repositories,
List<org.eclipse.aether.repository.RemoteRepository> resolverRepositories,
Lookup lookup) {
this.session = nonNull(session, "session");
this.session = requireNonNull(session, "session");
this.repositorySystem = repositorySystem;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Kind of inconsequent. Why not this? Nullable too. Thus session not marked @NonNull so its kind of magic number?

We produce boilerplate for the only difference to have a little better error message.

This is high cost for little, to almost no, return.

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.

4 participants