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 false positive with method inner classes · Issue #3701 · pmd/pmd

[java] MissingStaticMethodInNonInstantiatableClass false positive with method inner classes #3701

New issue
Copy link
New issue
Copy link
Closed
#3742
Closed
[java] MissingStaticMethodInNonInstantiatableClass false positive with method inner classes#3701
#3742
Copy link
Labels
a:false-positivePMD flags a piece of code that is not problematic
Milestone
6.42.0

Description

@hgschmie
hgschmie
opened on Dec 26, 2021
Issue body actions

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]

Activity

  1. hgschmie
    added
    a:false-positivePMD flags a piece of code that is not problematic
    on Dec 26, 2021
  2. dykov
    added a commit that references this issue on Jan 15, 2022

    pmd#3701 - fix MissingStaticMethodInNonInstantiatableClass for method…

    420505a
  3. adangel
    added this to the 6.42.0 milestone on Jan 17, 2022
  4. adangel
    closed this as completedin #3742on Jan 17, 2022
  5. adangel
    added 2 commits that reference this issue on Jan 17, 2022

    [doc] Update release notes (#3701, #3742)

    7688346

    Merge pull request pmd#3742 from dykov:hotfix/3701

    d49014c
  6. adangel
    closed this as completedin d49014con Jan 17, 2022
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-positivePMD flags a piece of code that is not problematic

    Type

    No type

    Projects

    No projects

      Milestone

      • 6.42.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.