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

[java] UselessParentheses false positive with boolean operators #1918

Closed
xuanuy opened this issue Jul 16, 2019 · 7 comments · Fixed by #2900
Closed

[java] UselessParentheses false positive with boolean operators #1918

xuanuy opened this issue Jul 16, 2019 · 7 comments · Fixed by #2900
Labels
a:false-positive PMD flags a piece of code that is not problematic
Milestone

Comments

@xuanuy
Copy link

xuanuy commented Jul 16, 2019

Affects PMD Version: 3.12.0

Rule: UselessParentheses

Description:
I have the condition if(a || b || (c & d) || e)
Then I get Useless parentheses violation message.

Code Sample demonstrating the issue:

if(a || b || (c & d) || e) {
 //do sth
}

Running PMD through: Maven

Java JDK 8

@oowekyala oowekyala added the a:false-positive PMD flags a piece of code that is not problematic label Jul 16, 2019
@AnthonyKot
Copy link
Contributor

@AnthonyKot
Copy link
Contributor

#1920

@adangel
Copy link
Member

adangel commented Jul 19, 2019

Since & has a higher precedence than ||, the rule correct in saying: The parentheses are not needed. See operator precedence.

However, in terms of readability, it's maybe better to allow these parentheses.
Similar discussion is here: #1673

Maybe we should give this rule a property to enable/disable something like a "strict" mode?

@adangel adangel changed the title [Java] UselessParentheses: catch wrong case [java] UselessParentheses false positive with boolean operators Nov 6, 2020
@adangel adangel added this to the 7.0.0 milestone Nov 6, 2020
@adangel adangel linked a pull request Nov 6, 2020 that will close this issue
4 tasks
@adangel
Copy link
Member

adangel commented Nov 6, 2020

Fixed with PMD 7

@adangel adangel closed this as completed Nov 6, 2020
@blacelle
Copy link

Where is PMD7? Latest seems 6.42.0 https://mvnrepository.com/artifact/net.sourceforge.pmd/pmd

@oowekyala
Copy link
Member

@blacelle PMD 7 is still in development, you can get daily snapshots from sourceforge and the sonatype snapshot repository.

The bug has been fixed in the PMD 7 development branch, but may still be present in PMD 6. I'll reopen the issue with the proper label (we didn't have this procedure yet when this bug was closed).

@adangel
Copy link
Member

adangel commented Apr 22, 2023

This has been fixed with PMD 7.0.0-rc1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:false-positive PMD flags a piece of code that is not problematic
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants