A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/pmd/pmd/issues/5590 below:

[java] LiteralsFirstInComparisonsRule not applied on constant · Issue #5590 · pmd/pmd · GitHub

Affects PMD Version: pmd:3.26.0

Rule: LiteralsFirstInComparisonsRule

Please provide the rule name and a link to the rule documentation:

https://pmd.github.io/pmd/pmd_rules_java_bestpractices.html#literalsfirstincomparisons

Description:

It is not found on the constant.
Is this indented correctly?
After briefly reviewing the code, I don't see any filtering, so this might be accidental.
A reference is always a potential NPE, in my opinion.
Therefore, the raw string literal should always come first.

Code Sample demonstrating the issue:

    static class Foo {
        private static final String FOO = null;

        public static void bar(String _null) {
            String _null2 = null;
            FOO.equals("RAW"); // not reported -> false-negative?
            _null.equals("RAW"); // is reported
            _null2.equals("RAW"); // is reported
        }
    }

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4