-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Modernize codebase with Java improvements #2277
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
Regarding point 2. (and the related point 4.): I consider the IAE more concise than an NPE in case a method argument is passed with null (although not allowed). Compare also with https://discuss.kotlinlang.org/t/why-does-requirenotnull-throw-an-illegalargumentexception/7617/4 |
I think that the main argument in favour of |
c52c814
to
b071032
Compare
Hi folks, please check out attached This could be supplemented in dedicated PR as there is a migration for this: Maybe we can team up with as its kind of related. The migration is "free" as done by one click so we can reproduce anytime. |
please consider this supplemental PR to apply SRP: |
its nice to fix this once, but without a computer checking and enforcing this by some tool like checkstyle or rewrite, its not completed. |
this is wrong. Only the upgradetojava21 recipe does the desired migration. Anyways the PR is now fixed. #2287 |
|
I don't see where it's done in your PR as it only provides the result of executing the transformation. |
@@ -337,7 +335,7 @@ public LocalRepository getLocalRepository() { | |||
@Nonnull | |||
@Override | |||
public Session withLocalRepository(@Nonnull LocalRepository localRepository) { | |||
nonNull(localRepository, "localRepository"); | |||
Objects.requireNonNull(localRepository, "localRepository cannot be null"); |
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.
Current State of NullPointerException
Handling
The current implementation around NullPointerException
is not ideal, but in context, it's clear what's happening.
Options:
- Keep it as-is
- Works but lacks elegance.
- Remove all such checks
- Simplifies but loses explicit null-check messaging.
- Refactor into a dedicated layer
- Separate the "cannot be null" concern to avoid:
- DRY violations (repetition)
- Feature envy (fluff and copy-paste)
- Separate the "cannot be null" concern to avoid:
Proposal: Dedicated Logging Layer
If improved logging is desired, this concern should be moved to a dedicated utility layer, similar to Apache Maven's approach:
throw new IllegalArgumentException(name + " cannot be null"); |
Benefits:
- Contextual clarity: Right now, the check is just a short "non-null" hint.
- Better debugging: Explicit messaging improves
NullPointerException
readability. - Consistency: Centralized handling avoids duplication.
This change is already reflected in PR #2290.
@@ -134,7 +132,7 @@ public AbstractSession( | |||
List<RemoteRepository> repositories, | |||
List<org.eclipse.aether.repository.RemoteRepository> resolverRepositories, | |||
Lookup lookup) { | |||
this.session = nonNull(session, "session"); |
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.
Current State of NullPointerException
Handling
The current implementation around NullPointerException
is not ideal, but in context, it's clear what's happening.
Options:
- Keep it as-is
- Works but lacks elegance.
- Remove all such checks
- Simplifies but loses explicit null-check messaging.
- Refactor into a dedicated layer
- Separate the "cannot be null" concern to avoid:
- DRY violations (repetition)
- Feature envy (fluff and copy-paste)
- Separate the "cannot be null" concern to avoid:
Proposal: Dedicated Logging Layer
If improved logging is desired, this concern should be moved to a dedicated utility layer, similar to Apache Maven's approach:
throw new IllegalArgumentException(name + " cannot be null"); |
Benefits:
- Contextual clarity: Right now, the check is just a short "non-null" hint.
- Better debugging: Explicit messaging improves
NullPointerException
readability. - Consistency: Centralized handling avoids duplication.
This change is already reflected in PR #2290.
@Pankraz76 I'm not sure what you aim for with your PRs. How do they differ from this one ? It's fine very fine that you used openrewrite rules, but isn't the result the same at the end ? |
Hello friend, yes thats the goal see reasoning below: Refactoring Large PRs: The Case for Atomic Changes/Why Smaller Changes WinKey Insight: Why Monolithic PRs Fail:
This PR's Structural Flaw:
The Atomic PR Advantage: The Granularity Paradox:
"These patterns persist because they survive Darwinian selection in production systems." |
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.
"Use modern Java collections API (toList() instead of collect(Collectors.toList()))" is riskier than the other changes because of the move of mutable to immutable lists. Nine times out of ten this is fine. The tenth time it's a bear to debug. These changes should be pulled out into a separate PR.
The rest could be split, but maybe don't have to be. Nuulable and Nonnull might also call for a separate PR.
Yes we working on a dedicated commit for each concern. Thanks Sent from my iPhoneOn 5 May 2025, at 12:41, Elliotte Rusty Harold ***@***.***> wrote:
@elharo requested changes on this pull request.
"Use modern Java collections API (toList() instead of collect(Collectors.toList()))" is riskier than the other changes because of the move of mutable to immutable lists. Nine times out of ten this is fine. The tenth time it's a bear to debug. These changes should be pulled out into a separate PR.
The rest could be split, but maybe don't have to be. Nuulable and Nonnull might also call for a separate PR.
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you were mentioned.Message ID: ***@***.***>
|
Java and Lombok prefer NPE as well. https://docs.oracle.com/javase/8/docs/api/java/util/Objects.html#requireNonNull-T- https://projectlombok.org/features/NonNull both valid points. Ideally its just one config-switch to adjust: ![]() |
There 's no plan to use Lombok at this point. |
This PR includes several improvements to modernize the codebase:
These changes make the code more maintainable, safer, and aligned with modern Java practices.