Skip to content
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

ReplaceDuplicateStringLiterals throws NPE from 1.19.0+ #384 #385

Merged
merged 5 commits into from
Jan 11, 2025

Conversation

adambir
Copy link
Contributor

@adambir adambir commented Oct 30, 2024

What's changed?

Added a test for issue #384 on the ReplaceDuplicateStringLiterals recipe.

What's your motivation?

Allow reproduction of the bug

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

@timtebeek timtebeek changed the title Add test case for issue #384 ReplaceDuplicateStringLiterals throws NPE from 1.19.0+ #384 Oct 30, 2024
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@timtebeek timtebeek marked this pull request as ready for review January 11, 2025 14:36
@timtebeek timtebeek added the bug Something isn't working label Jan 11, 2025
Copy link
Contributor

@timtebeek timtebeek left a comment

Choose a reason for hiding this comment

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

Thanks for the clear report here @adambir ! Turns out my IDE warned about the same potential NPE that you were seeing. Fixed now by adjusting the condition just above.

@timtebeek timtebeek merged commit 871554c into openrewrite:main Jan 11, 2025
2 checks passed
@Bananeweizen
Copy link
Contributor

@timtebeek Would you mind checking this fix again? The previous logic was effectively "! instanceof String", and the negation is lost now. While I can't really judge the overall condition, the code after the if-condition supports my claim: In line 236 is an explicit getValue().toString() (indicating this is not instanceof String yet). Compare that to line 242, where getValue() is taken directly after checking instanceof String.

timtebeek added a commit that referenced this pull request Jan 12, 2025
@timtebeek
Copy link
Contributor

Keen eye there! I've restored the original conditiona and added another to indeed handle these cases correctly, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

ReplaceDuplicateStringLiterals throws java.lang.NullPointerException on version 1.19.0
4 participants