-
Notifications
You must be signed in to change notification settings - Fork 60
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
WIP: Fix PMD rule LiteralsFirstInComparisons for compareTo* and contentEquals #448
base: main
Are you sure you want to change the base?
Conversation
1f33b73
to
b38ff0a
Compare
I need to fix my setup to get this running. It should be almost there, right? I think it's better to deliver something now rather than waiting longer. Feel free to take over and provide early feedback if this seems like the right direction. Thanks |
…ns-for-compareTo-and-contentEquals' into Fix-PMD-rule-LiteralsFirstInComparisons-for-compareTo-and-contentEquals
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
feel free to takeover and give feedback, thx.
style = Checkstyle.equalsAvoidsNull(); | ||
return Preconditions.check( | ||
// new UsesMethod<>("java.lang.String *quals*(..)"), | ||
new UsesMethod<>("java.lang.String *(..)"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @timtebeek,
I need help finding a better regex for equals and compareTo. The current one is just a temporary fix—it might work, but it's inefficient.
} | ||
}; | ||
return Preconditions.check( | ||
new UsesMethod<>("java.lang.String *quals*(..)"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed this by accident while wondering why the recipe wasn’t applied. I think it would be better to prioritize a functional approach—putting the most important things first. In a functional style, it’s easier to see and understand the flow right away.
Thanks for considering this!
@@ -447,6 +499,15 @@ public class A { | |||
System.out.println(s.compareToIgnoreCase("test")); | |||
} | |||
} | |||
""", | |||
""" | |||
public class A { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’m not sure why we don’t have a second comparison method here—you guys probably know better. Looking at the code, it seems like the goal is to avoid an NPE.
This test was the only one failing, which caught my attention, so I decided to conclude it and ask the team for their thoughts.
Thanks!
#362