GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [java] MissingStaticMethodInNonInstantiatableClass should consider Lombok's @UtilityClass · Issue #4224 · pmd/pmd

[java] MissingStaticMethodInNonInstantiatableClass should consider Lombok's @UtilityClass #4224

New issue
Copy link
New issue
Copy link
Closed
#4228
Closed
[java] MissingStaticMethodInNonInstantiatableClass should consider Lombok's @UtilityClass#4224
#4228
Copy link
Labels
a:false-negativePMD doesn't flag a problematic piece of code
Milestone
6.52.0

Description

@ghost
ghost
opened on Nov 22, 2022

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

Activity

  1. ghost added
    a:false-negativePMD doesn't flag a problematic piece of code
    on Nov 22, 2022
  2. ghost changed the title [-]MissingStaticMethodInNonInstantiatableClass should considers lombok's UtilityClass[/-] [+][java] MissingStaticMethodInNonInstantiatableClass should considers lombok's UtilityClass[/+] on Nov 22, 2022
  3. adangel
    modified the milestones: 6.53.0, 6.52.0 on Nov 22, 2022
  4. adangel
    changed the title [-][java] MissingStaticMethodInNonInstantiatableClass should considers lombok's UtilityClass[/-] [+][java] MissingStaticMethodInNonInstantiatableClass should consider Lombok's UtilityClass[/+] on Nov 24, 2022
  5. adangel
    changed the title [-][java] MissingStaticMethodInNonInstantiatableClass should consider Lombok's UtilityClass[/-] [+][java] MissingStaticMethodInNonInstantiatableClass should consider Lombok's @UtilityClass[/+] on Nov 24, 2022
  6. adangel
    modified the milestones: 6.52.0, 6.53.0 on Nov 24, 2022
  7. adangel
    added 2 commits that reference this issue on Nov 25, 2022

    [doc] Update release notes (pmd#4224, pmd#4228)

    bc210b4

    Merge pull request pmd#4228 from LynnBroe:issue4224

    cb7c07f
  8. adangel
    closed this as completedin #4228on Nov 25, 2022
  9. dawiddc commented on Feb 14, 2023

    @dawiddc
    dawiddc
    on Feb 14, 2023
    Contributor
    More actions

    @adangel @LynnBroe Now there are false positives for @UtilityClass classes that have no methods but have only non-private fields e.g. public static final String TOKEN_HEADER = "token-validated";

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    a:false-negativePMD doesn't flag a problematic piece of code

    Type

    No type

    Projects

    No projects

      Milestone

      • 6.52.0

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.