A RetroSearch Logo

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

Search Query:

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

false positive with builder pattern · Issue #5068 · pmd/pmd · GitHub

Affects PMD Version:
7.2.0

Rule:
MissingStaticMethodInNonInstantiatableClass
https://docs.pmd-code.org/latest/pmd_rules_java_errorprone.html#missingstaticmethodinnoninstantiatableclass

Description:
Under certain circumstances, classes are identified as non-instantiatable, and then trigger the rule, even though the class can in fact be instantiated.

Code Sample demonstrating the issue:

public class MyClass {

    private MyClass() {
    }

    public static class Builder {

        private Builder() {

        }

        public static Builder builder() {
            return new Builder();
        }

        public MyClass build() {
            return new MyClass();
        }

    }

}

Expected outcome:

PMD reports a violation at line 1, but that's wrong. That's a false positive. The class can be instantiated with Builder.builder().build().

Running PMD through: Gradle


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