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] PublicMemberInNonPublicType: False positive for `main(...)` methods · Issue #6459 · pmd/pmd

[java] PublicMemberInNonPublicType: False positive for main(...) methods #6459

New issue
Copy link
New issue
Copy link
Closed
#6804
Closed
[java] PublicMemberInNonPublicType: False positive for main(...) methods#6459
#6804
Copy link
Labels
a:false-positivePMD flags a piece of code that is not problematic
Milestone
7.26.0

Description

@uhafner
uhafner
opened on Feb 15, 2026
Issue body actions

Affects PMD Version: 7.22.0

Rule: PublicMemberInNonPublicType

Please provide the rule name and a link to the rule documentation:

Description:

The new rule flags the usage of the main method in non public classes. I think only newer JDK version allow main methods to be non-public.

Code Sample demonstrating the issue:

class MyTest {
    public static void main(final String... args)  {
        // main method that is invoked in IntelliJ
    }
}

Expected outcome:

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

Running PMD through: Maven

Caused by: #6231

Activity

  1. uhafner
    added
    a:false-positivePMD flags a piece of code that is not problematic
    on Feb 15, 2026
  2. uhafner commented on Feb 15, 2026

    @uhafner
    uhafner
    on Feb 15, 2026
    Author
    More actions

    BTW: In order to ignore the violation I need to suppress on the type and not on the affected method, it would be nice if that can be changed as well. (As shown in https://github.com/jenkinsci/analysis-model/blob/666ae125babdfb716e5c1c5198acf01559a7f008/src/test/java/edu/hm/hafner/analysis/IssueTest.java#L362 this works for methods)

  3. uhafner
    changed the title [-]PublicMemberInNonPublicType should ignore `main` methods[/-] [+]`PublicMemberInNonPublicType` should ignore `main` methods[/+] on Feb 15, 2026
  4. adangel
    changed the title [-]`PublicMemberInNonPublicType` should ignore `main` methods[/-] [+][java] PublicMemberInNonPublicType: False positive for `main(...)` methods[/+] on Feb 16, 2026
  5. UncleOwen commented on Jun 21, 2026

    @UncleOwen
    UncleOwen
    on Jun 21, 2026
    Member
    More actions

    Is this really a false positive?

    In Java < 25 (ignoring previews), this isn't a valid entry point.

    In Java >= 25, you can write this as

    class MyTest {
        void main(final String... args)  {
            // main method that is invoked in IntelliJ
        }
    }

    or even

    void main(final String... args)  {
        // main method that is invoked in IntelliJ
    }

    In both cases, I'd say that the warning is justified?

  6. uhafner commented on Jun 21, 2026

    @uhafner
    uhafner
    on Jun 21, 2026
    Author
    More actions

    Is this really a false positive?

    In Java < 25 (ignoring previews), this isn't a valid entry point.

    It is a valid entry point in Java < 25. Why should this not be possible?

    I am using this part in a lot of my test cases, example: https://github.com/jenkinsci/analysis-model/blob/666ae125babdfb716e5c1c5198acf01559a7f008/src/test/java/edu/hm/hafner/analysis/IssueTest.java#L362

  7. UncleOwen commented on Jun 21, 2026

    @UncleOwen
    UncleOwen
    on Jun 21, 2026
    Member
    More actions

    Huh. I could have sworn that main had to be in a public class in java < 25. You're right, I was wrong. This is indeed valid.

  8. adangel
    added this to the 7.26.0 milestone on Jun 23, 2026
  9. adangel
    added a commit that references this issue on Jun 23, 2026

    PublicMemberInNonPublicType: Don't trigger on main method (#6459)

    1f02b2b
  10. adangel
    closed this as completedin #6804on Jun 23, 2026
  11. adangel
    added a commit that references this issue on Jun 23, 2026

    [java] Fix #6459: special case main in PublicMemberInNonPublicType (#…

    This issue will close once commit 6c60e42 is merged into the 'main' branch.
    6c60e42
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

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