-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
[java] UselessParentheses false positive with conditional operator #1673
Comments
@Vampire the rule will detect any pair of parenthesis that can be removed without affecting the code's behavior. As such, this being reported is effectively ok. As for the enhancement… I guess the thing is how far we need to go… I mean, I know people tend to have trouble remembering wether I'm unsure what a sane set of properties and what scenarios they allow will be intuitive for users and reasonable to maintain. |
Then the rule has a false-negative instead. throw new IllegalArgumentException(String.format(
"Unsupported client with class '%s' given",
(discordClient == null ? null : discordClient.getClass()))); useless parantheses are found, in throw new IllegalArgumentException(String.format(
"Unsupported client with class '%s' given",
(discordClient == null) ? null : discordClient.getClass())); they are not. While I also here want the parentheses to stay for easier reading. True, finding a sane set of what to report and what not that works for all is probably impossible. :-( |
For comparison, the IntelliJ inspection has a property to ignore parentheses when the inner and outer operators have different precedences. That's is not very configurable, but it's simple and makes sense. |
Ok, that one is a FP, so I'm updating the issue. I think the enhancement needs some further discussion, so maybe we should create a separate ticket. |
Maybe better a separate ticket for the FP to have the discussion so far here and rename this to the enhancement request? |
Fixed with PMD 7 |
Affects PMD Version: 6.11.0
Rule: UselessParentheses
Code Sample demonstrating the issue:
Additionally, should we add properties to allow whitelisting some scenarios, such as this one?
Running PMD through: Gradle
The text was updated successfully, but these errors were encountered: