Skip to content

[java] MissingStaticMethodInNonInstantiatableClass: False positive with multiple top-level classes #4531

Closed

Description

@jiayiw2008

Affects PMD Version:7.0.0-rc1

Rule: MissingStaticMethodInNonInstantiatableClass

Description:
The rule fails to properly handle when there is more than one top-level class.

In the following example, Bar2 is correctly flagged by the rule, but as a top-level class is annotated with @UtilityClass, all top-level classes are analyzed as if annotated, and hence Bar1 is also flagged.

Code Sample demonstrating the issue:

import lombok.experimental.UtilityClass;
class Bar1 {}    //  report a warning, but this is a FP
@UtilityClass
class Bar2 {}    //  report a warning

The problem lies with this line:

let $isLombokUtility := exists($topLevelClass[pmd-java:hasAnnotation('lombok.experimental.UtilityClass')]) return

This exists check is not bound to the particular top-level class being analyzed.

Expected outcome:

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

Activity

  1. added
    a:false-positive
    on May 2, 2023
  2. added
    needs:pmd7-revalidation
    and removed
    needs:pmd7-revalidation
    on Mar 17, 2024
  3. changed the title [-][java] A false positive about MissingStaticMethodInNonInstantiatableClass[/-] [+][java] MissingStaticMethodInNonInstantiatableClass: False positive with multiple top-level classes[/+] on Dec 19, 2025
  4. added a commit that references this issue on Oct 27, 2026
    98340ff
  5. added this to the 7.30.0 milestone on Nov 6, 2026
  6. added a commit that references this issue on Nov 6, 2026
    cff7d9d
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-positive

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions