A RetroSearch Logo

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

Search Query:

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

[java] MissingStaticMethodInNonInstantiatableClass false positive with method inner classes · Issue #3701 · pmd/pmd · GitHub

Affects PMD Version: 6.41.0

Rule: MissingStaticMethodInNonInstantiatableClass

Please provide the rule name and a link to the rule documentation:
https://pmd.github.io/latest/pmd_rules_java_errorprone.html#missingstaticmethodinnoninstantiatableclass

Description:

Using a method nested class causes a false positive:

PMD Failure: Scratch$InnerClass:11 Rule:MissingStaticMethodInNonInstantiatableClass Priority:3 Class cannot be instantiated and does not provide any static methods or fields.

Code Sample demonstrating the issue:

public class Scratch {

    public static void main(String[] args) {
        Scratch scratch = new Scratch();

        scratch.callMethod();
    }

    void callMethod() {

        class InnerClass {
            private InnerClass() {
            }

            void display() {
                System.out.println("Works OK!");
            }
        }

        InnerClass innerClass = new InnerClass();
        innerClass.display();
    }
}

This code compiles just fine and running it prints Works OK!.

Expected outcome:

PMD understands this code just fine

PMD reports a violation at line 11, but that's wrong. That's a false positive.

Running PMD through: [Maven]


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