Skip to content

Handling parentheses sometimes needed around instanceof #521

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

Merged

Conversation

greg-at-moderne
Copy link
Contributor

What's changed?

Fixing ReplaceClassIsInstanceWithInstanceof wrt to parenthesis being sometimes needed around the instanceof.

What's your motivation?

Fix the errors observed in real-life, e.g.
this code in spring-hateoas throws:

Message:

class org.openrewrite.java.tree.J$Parentheses cannot be cast to class org.openrewrite.java.tree.J$InstanceOf (org.openrewrite.java.tree.J$Parentheses and org.openrewrite.java.tree.J$InstanceOf are in unnamed module of loader 'app')
Detail:

java.lang.ClassCastException: class org.openrewrite.java.tree.J$Parentheses cannot be cast to class org.openrewrite.java.tree.J$InstanceOf (org.openrewrite.java.tree.J$Parentheses and org.openrewrite.java.tree.J$InstanceOf are in unnamed module of loader 'app')
  org.openrewrite.staticanalysis.ReplaceClassIsInstanceWithInstanceof$1.visitMethodInvocation(ReplaceClassIsInstanceWithInstanceof.java:73)
  org.openrewrite.staticanalysis.ReplaceClassIsInstanceWithInstanceof$1.visitMethodInvocation(ReplaceClassIsInstanceWithInstanceof.java:60)

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Some suggestions could not be made:

  • src/test/java/org/openrewrite/staticanalysis/RemoveUnusedPrivateMethodsTest.java
    • lines 101-101

@@ -33,6 +33,7 @@
import org.openrewrite.java.tree.JavaType;

import java.util.Collections;
import java.util.function.Function;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
import java.util.function.Function;
import java.util.function.Function;

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Some suggestions could not be made:

  • src/test/java/org/openrewrite/staticanalysis/RemoveUnusedPrivateMethodsTest.java
    • lines 101-102

@@ -33,6 +33,7 @@
import org.openrewrite.java.tree.JavaType;

import java.util.Collections;
import java.util.function.Function;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
import java.util.function.Function;
import java.util.function.Function;

@greg-at-moderne greg-at-moderne merged commit 4abfa6c into main Apr 18, 2025
2 checks passed
@greg-at-moderne greg-at-moderne deleted the greg-ReplaceClassIsInstanceWithInstanceof-parens branch April 18, 2025 13:09
@github-project-automation github-project-automation bot moved this from In Progress to Done in OpenRewrite Apr 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

1 participant