Skip to content

Conversation

@scordio
Copy link
Member

@scordio scordio commented Jan 30, 2025

@scordio scordio added this to the 4.0.0-M1 milestone Jan 30, 2025
@scordio scordio force-pushed the openrewrite-java-17 branch 2 times, most recently from a0aa352 to 2de7b56 Compare January 30, 2025 23:52
@scordio scordio marked this pull request as ready for review January 31, 2025 00:31
// Special handle SortedSets because they are fast to compare
// because their elements must be in the same order to be equivalent Sets.
if (key1 instanceof Collection<?> set) {
if (key1 instanceof SortedSet<?> set) {
Copy link
Member Author

@scordio scordio Jan 31, 2025

Choose a reason for hiding this comment

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

Hi @timtebeek! May I ask your opinion on this one?

I executed the Java 17 recipe on the AssertJ codebase, and as far as I can tell, there was an incorrect migration.

Initially, it was:

if (key1 instanceof SortedSet) {
if (!compareOrderedCollection((Collection<?>) key1, (Collection<?>) key2, currentPath, toCompare, visited)) {

and, after the recipe run, became:

-      if (key1 instanceof SortedSet) {
-        if (!compareOrderedCollection((Collection<?>) key1, (Collection<?>) key2, currentPath, toCompare, visited)) {
+      if (key1 instanceof Collection<?> set) {
+        if (!compareOrderedCollection(set, (Collection<?>) key2, currentPath, toCompare, visited)) {

Do you think it's something to report as an OpenRewrite issue?

Choose a reason for hiding this comment

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

Apologies for the late reply! I was out 🏂🏻. Indeed looks like a bug; I think it's best not to make any change if there's a mismatch between the righthand side of the instanceof and the cast. Would you mind logging an issue? I'm catching up here still.

Great to see you're running these recipes; I hope they've helped you so far already.

Copy link
Member Author

Choose a reason for hiding this comment

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

No worries!

Yes, they definitely helped! Still going through the review of the 400+ files 🙃

I'll log an issue in the upcoming days 👍


// Check List, as element order matters this comparison is faster than using unordered comparison.
if (key1 instanceof Collection<?> list) {
if (key1 instanceof List<?> list) {
Copy link
Member Author

@scordio scordio Jan 31, 2025

Choose a reason for hiding this comment

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

@timtebeek this is the second one, which originally was:

if (key1 instanceof List) {
if (!compareOrderedCollection((Collection<?>) key1, (Collection<?>) key2, currentPath, toCompare, visited)) {

and, after the recipe run, became:

-      if (key1 instanceof List) {
-        if (!compareOrderedCollection((Collection<?>) key1, (Collection<?>) key2, currentPath, toCompare, visited)) {
+      if (key1 instanceof Collection<?> list) {
+        if (!compareOrderedCollection(list, (Collection<?>) key2, currentPath, toCompare, visited)) {

@scordio scordio force-pushed the openrewrite-java-17 branch 11 times, most recently from 78d4196 to 3daa3c1 Compare February 2, 2025 22:09
@scordio scordio force-pushed the openrewrite-java-17 branch from 3daa3c1 to c352ade Compare February 2, 2025 22:11
@scordio scordio merged commit e96aab4 into main Feb 2, 2025
27 checks passed
@scordio scordio deleted the openrewrite-java-17 branch February 2, 2025 22:18
alanktwong pushed a commit to alanktwong/assertj that referenced this pull request Feb 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants