Menu

#1256 PositionLiteralsFirstInComparisons false positive with Characters

PMD-5.2.1
closed
None
PMD
4-Minor
Bug
5.1.3
2014-11-03
2014-09-03
No

The following class triggers a PositionLiteralsFirstInComparisons violation:

public class LiteralTest {

    protected final boolean check;

    public LiteralTest(Character c) {
        check = c.equals('x');
    }

}

There are two issues with this:

  1. One can't just switch the variables and write 'x'.equals(c)

  2. The error message ("Position literals first in String comparisons") seems to imply that this should be checking only String literals -- not char literals.

Discussion

  • Andreas Dangel

    Andreas Dangel - 2014-11-02
    • summary: PositionLiteralsFirstInComparisons false positive --> PositionLiteralsFirstInComparisons false positive with Characters
    • status: open --> in-progress
    • assigned_to: Andreas Dangel
    • Milestone: New Tickets --> PMD-next
     
  • Andreas Dangel

    Andreas Dangel - 2014-11-03
    • status: in-progress --> closed
     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.