-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
base: master
Are you sure you want to change the base?
Conversation
impl/maven-impl/src/test/java/org/apache/maven/impl/DefaultModelXmlFactoryTest.java
Show resolved
Hide resolved
Modernize codebase with Java improvements - Replace custom null checks with Objects.requireNonNull
Modernize codebase with Java improvements - Replace custom null checks with Objects.requireNonNull
… custom null checks with Objects.requireNonNull
Modernize codebase with Java improvements - Replace custom null checks with Objects.requireNonNull
Objects.requireNonNull
impl/maven-impl/src/main/java/org/apache/maven/impl/ImplUtils.java
Outdated
Show resolved
Hide resolved
… custom null checks with Objects.requireNonNull
… custom null checks with Objects.requireNonNull
|
||
@Named | ||
@Singleton | ||
public class DefaultArtifactCoordinatesFactory implements ArtifactCoordinatesFactory { | ||
@Override | ||
public ArtifactCoordinates create(@Nonnull ArtifactCoordinatesFactoryRequest request) { | ||
nonNull(request, "request"); |
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.
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
:

@@ -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; |
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.
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.
Pull #2290: Modernize codebase with Java improvements - Replace custom null checks with
Objects.requireNonNull
toList()
instead ofCollectors.toList()
) #2287