[java] SimplifiedTernary: False positive with ternary operator
A source code analyzer
Brought to you by:
adangel,
juansotuyo
I get Ternary operators that can be simplified with || or && on this piece of code:
private SomeValue doStuff(SomeValue someValue) { return THE_VALUE.equals(rangeValue.to) ? new SomeValue(someValue.from, null, true) : someValue; }
It works if I change to return THE_VALUE.equals(rangeValue.to) ? new SomeValue(someValue.from) : someValue;
False positive, not a false negative. I've seen this one too.
The XPath query matches any BooleanLiteral in the ternary subtrees - it should match just the literals directly (full AST path to literal): https://pmd.github.io/pmd-5.4.0/pmd-java/rules/java/basic.html#SimplifiedTernary
This bug will be fixed with PMD 5.4.2 and later.
Commit: https://github.com/pmd/pmd/commit/cfaaf2f52ae791ed02347c1b8dbb1aa859435510