Conversation
gnodet
left a comment
There was a problem hiding this comment.
The problem is that this code change is not semantically the same. The stream.collect(Collectors.toList()) returns a mutable list, while stream.toList() returns an immutable collection.
So this cannot be applied blindly using a recipe imho.
on greenfield yes, to ensure https://adabeat.com/fp/immutability-in-functional-programming/ for legacy, or valid exceptions, like maven we need suppression. |
yes we can: make change and wrap in Then we have same API, but no new violations following: https://kyleshevlin.com/just-enough-fp-immutability/ |
| return method.getArguments().get(0) instanceof J.MethodInvocation && | ||
| ((J.MethodInvocation) method.getArguments().get(0)).getSimpleName().equals("toList") && | ||
| ((J.MethodInvocation) method.getArguments().get(0)).getSelect() != null && | ||
| ((J.MethodInvocation) method.getArguments().get(0)).getSelect().toString().equals("Collectors"); |
There was a problem hiding this comment.
This would fail to pick up static imports of toList. Wherever possible prefer to use MethodMatchers as opposed to looking at simple names, as that avoids these pitfalls.
src/test/java/org/openrewrite/staticanalysis/ReplaceCollectToListWithToListTest.java
Show resolved
Hide resolved
src/main/java/org/openrewrite/staticanalysis/ReplaceCollectToListWithToList.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/staticanalysis/ReplaceCollectToListWithToList.java
Outdated
Show resolved
Hide resolved
src/test/java/org/openrewrite/staticanalysis/ReplaceCollectToListWithToListTest.java
Outdated
Show resolved
Hide resolved
…istWithToList.java Co-authored-by: Tim te Beek <timtebeek@gmail.com>
…istWithToList.java Co-authored-by: Tim te Beek <timtebeek@gmail.com>
…istWithToListTest.java Co-authored-by: Tim te Beek <timtebeek@gmail.com>
…istWithToListTest.java Co-authored-by: Tim te Beek <timtebeek@gmail.com>
|
recent discovery seems fishy -
then |
|
I've spoken at length with the author linked above at Code Remix Summit last week, helped him understand and analyze the changes, and got him set up to continue his work. Despite this he came out with a deeply flawed analysis and false statements, which unfortunately are being taken at face value. Figured I'd provide some more context about the changes made from our perspective: You're all welcome to use and contribute to OpenRewrite for as much as you'd like; we see no reason to be hesitant at all, but understand opinions may differ. |
rewrite-maven-plugin: Introduce OpenRewrite by Moderne apache/maven#2322FYI: @gnodet @elharo
need suppression support for old API then we can fix it
once. @timtebeek