A RetroSearch Logo

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

Search Query:

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

[java] MissingStaticMethodInNonInstantiatableClass should consider Lombok's @UtilityClass · Issue #4224 · pmd/pmd · GitHub

Affects PMD Version:6.51.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:
In the following code example, the @UtilityClass generates a private constructor private Test() which throws an exception.So the class only has a private constructor and does not have any static methods or fields which cannot be used. But PMD considers the class doesn't have a constructor and does not report MissingStaticMethodInNonInstantiatableClass at line 4 which causes false negatives.

Lombok documentation: https://projectlombok.org/features/experimental/UtilityClass

Code Sample demonstrating the issue:

Original code:

import lombok.experimental.UtilityClass;

@UtilityClass
public final class Test {
    private int x;
}

Changed:

public final class Test {
    private static int x;

    private Test() {
        throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
    }
}

Expected outcome:

PMD should report a violation at line 4, but not. That's a false negative.

Running PMD through: CLI


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