rewrite-spring icon indicating copy to clipboard operation
rewrite-spring copied to clipboard

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

Open timtebeek opened this issue 1 year ago • 0 comments

The replacement done on these lines is incorrect when it concerns empty collections, is what I'm told on Discord: https://github.com/openrewrite/rewrite-spring/blob/71fbf7c27536877c47b28e85a13f0f4629d6b5de/src/main/resources/META-INF/rewrite/spring-framework-53.yml#L47-L54

earlier a List<Object> 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

timtebeek avatar Jan 12 '24 05:01 timtebeek