Menu

#1424 [java] SimplifiedTernary: False positive with ternary operator

PMD-5.4.2
closed
java (55)
PMD
3-Major
Bug
5.4.0
java-basic/SimplifiedTernary
2016-06-25
2015-10-07
mingoto
No

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;

Discussion

  • HairyFotr

    HairyFotr - 2015-12-04

    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

     
  • Andreas Dangel

    Andreas Dangel - 2016-02-01
    • summary: False negative with ternary operator --> False positive with ternary operator
    • status: open --> closed
    • assigned_to: Andreas Dangel
    • Milestone: New Tickets --> PMD-5.4.2
     
  • Andreas Dangel

    Andreas Dangel - 2016-02-01
    • Ruleset / Rule: --> java-basic/SimplifiedTernary
     
  • Andreas Dangel

    Andreas Dangel - 2016-06-25
    • labels: --> java
    • summary: False positive with ternary operator --> [java] SimplifiedTernary: False positive with ternary operator
     

Log in to post a comment.