Skip to content

add ObjectUtils.getNonNull/getIfNull/getIfEmpty #34587

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

Closed
wants to merge 4 commits into from

Conversation

Pankraz76
Copy link

@Pankraz76 Pankraz76 commented Mar 13, 2025

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Mar 13, 2025
@Pankraz76 Pankraz76 force-pushed the add-getIfNull branch 7 times, most recently from 6c89864 to d624371 Compare March 13, 2025 09:37
@Pankraz76 Pankraz76 marked this pull request as ready for review March 13, 2025 09:38
@Pankraz76 Pankraz76 changed the title add ObjectUtils.defaultIfNull add ObjectUtils.defaultIfNull/defaultIfEmpty Mar 13, 2025
@Pankraz76 Pankraz76 changed the title add ObjectUtils.defaultIfNull/defaultIfEmpty add ObjectUtils.getIfNull/getIfEmpty Mar 13, 2025
Signed-off-by: Vincent Potucek <[email protected]>
@Pankraz76
Copy link
Author

Pankraz76 commented Mar 13, 2025

is this any good? @currenjin @bclozel

Copy link

@currenjin currenjin left a comment

Choose a reason for hiding this comment

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

Wow, this is amazing! Thank you for going above and beyond by adding the getIfNull utility method. This is exactly what we needed for more concise code.

I really appreciate your dedication to improving the codebase and making this PR even better. The method looks well-designed with good documentation and examples.

This demonstrates what makes the Spring community so great - collaborative improvement and attention to detail. I'll definitely use this in my implementation to make the code more elegant.

Thank you again for your exceptional contribution!

@Pankraz76 Pankraz76 changed the title add ObjectUtils.getIfNull/getIfEmpty add ObjectUtils.getNonNull/getIfNull/getIfEmpty Mar 13, 2025
* @return An Optional containing the first non-null object, or an empty Optional if all objects are null.
*/
@SafeVarargs
public static <T> Optional<T> getNonNull(@Nullable final T... objects) {
Copy link
Author

Choose a reason for hiding this comment

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

this would have the bigger impact imho @currenjin

@Pankraz76 Pankraz76 force-pushed the add-getIfNull branch 2 times, most recently from 5a89550 to 3470df0 Compare March 14, 2025 07:09
@bclozel
Copy link
Member

bclozel commented Mar 14, 2025

Thanks for your enthusiasm, but we are limiting the scope of our *Utils classes on purpose. Our goal is to maintain a very limited number of methods that are widely useful in the Spring Framework codebase and do not intend to be a shared utility library like Apache commons. Those methods are public because they need to be used from various places in our codebase, but we don't think that application code should depend on it.

Ultimately, adding/removing methods in Utils classes is mainly a Framework team call. We know the community is using those anyway, but whenever we get contributions for performance improvements, we always consider the use cases in Spring Framework and ignore others. In that sense, Apache commons and similar libraries are a much better fit.

I would suggest focusing on the original PR in this case.
Thanks!

@bclozel bclozel closed this Mar 14, 2025
@bclozel bclozel added status: declined A suggestion or change that we don't feel we should currently apply and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Mar 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: declined A suggestion or change that we don't feel we should currently apply
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants