Skip to content
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

StringUtils#isEmpty is not equivalent to ObjectUtils#isEmpty for collections #475

Open
timtebeek opened this issue Jan 12, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@timtebeek
Copy link
Contributor

The replacement done on these lines is incorrect when it concerns empty collections, is what I'm told on Discord:

type: specs.openrewrite.org/v1beta/recipe
name: org.openrewrite.java.spring.framework.UseObjectUtilsIsEmpty
displayName: Use `ObjectUtils#isEmpty(Object)`
description: '`StringUtils#isEmpty(Object)` was deprecated in 5.3.'
recipeList:
- org.openrewrite.java.ChangeMethodTargetToStatic:
methodPattern: org.springframework.util.StringUtils isEmpty(Object)
fullyQualifiedTargetTypeName: org.springframework.util.ObjectUtils

earlier a List list was passed, which was coming as null from a rest API call. Then the REST call started returning an emptyList() instead which was not null. But the stricter check in ObjectUtils now checks if its any collection and the collection is empty or not.
Its an idiosyncracy from our codebase, but the expectation from rewrite plugin was the code changes would be one-to-one, just a null check like the last impl of StringUtils would have been fine. Making it more stricter broke the expected flow
Ideally if you are not passing any sort of Collection to StringUtils.isEmpty() you are good to replace

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Backlog
Development

Successfully merging a pull request may close this issue.

1 participant