Skip to content

Fix ClassCastException for valueMatches in AddOrUpdateAnnotationAttribute #5913

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

jevanlingen
Copy link
Contributor

What's changed?

Improved check to be sure no ClassCastException can occur.

What's your motivation?

If an Unknown typed JavaType is used as constant, a

Caused by: java.lang.ClassCastException: class org.openrewrite.java.tree.J$FieldAccess cannot be cast to class org.openrewrite.java.tree.J$Identifier (org.openrewrite.java.tree.J$FieldAccess and org.openrewrite.java.tree.J$Identifier are in unnamed module of loader 'app')

is thrown.

Checklist

  • I've added unit tests to cover both positive and negative cases
  • I've read and applied the recipe conventions and best practices
  • I've used the IntelliJ IDEA auto-formatter on affected files

@jevanlingen jevanlingen self-assigned this Aug 14, 2025
@jevanlingen jevanlingen added bug Something isn't working recipe Requested Recipe labels Aug 14, 2025
@github-project-automation github-project-automation bot moved this to In Progress in OpenRewrite Aug 14, 2025
@jevanlingen jevanlingen moved this from In Progress to Ready to Review in OpenRewrite Aug 14, 2025
github-actions[bot]

This comment was marked as spam.

github-actions[bot]

This comment was marked as spam.

@jevanlingen jevanlingen merged commit d428398 into main Aug 14, 2025
2 checks passed
@jevanlingen jevanlingen deleted the AddOrUpdateAnnotationAttribute-prevent-cast-expression branch August 14, 2025 09:17
@github-project-automation github-project-automation bot moved this from Ready to Review to Done in OpenRewrite Aug 14, 2025
dcsekar pushed a commit to dcsekar/rewrite that referenced this pull request Aug 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working recipe Requested Recipe
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants