Skip to content

[java] PublicMemberInNonPublicType: False negative for overridden methods #6460

Closed

Description

@uhafner

Affects PMD Version: 7.22.0

Rule: PublicMemberInNonPublicType

Description:

The new rule does not flag methods, when they are overridden in sub classes with the wrong visibility.

Code Sample demonstrating the issue:

class Outer {
    public void detected() {
        // this method is correctly detected
    }

    void notDetected() {
        // this method is correctly not detected here because it is package private
    }

    static class Nested extends Outer {
        public void nestedMethod() {
            // this method is correctly detected
        }

        @Override
        public void notDetected() {
            // this one should be detected now, but is not
        }
    }
}

Expected outcome:

PMD should report 3 violations, but does report only 2.

[WARNING] PMD Failure: edu.hm.hafner.grading.Outer:4 Rule:PublicMemberInNonPublicType Priority:3 Public member 'detected' declared in a non-public type.
[WARNING] PMD Failure: edu.hm.hafner.grading.Outer.Nested:13 Rule:PublicMemberInNonPublicType Priority:3 Public member 'nestedMethod' declared in a non-public type.

Running PMD through: Maven

Activity

  1. added
    a:false-negative
    on Feb 15, 2026
  2. changed the title [-]`PublicMemberInNonPublicType` does not detect overridden methods[/-] [+][java] PublicMemberInNonPublicType: False negative for overridden methods[/+] on Feb 16, 2026
  3. added 4 commits that reference this issue on Jun 21, 2026
    8342ab9
    825305b
    c1d402c
    b8ca2d2
  4. added this to the 7.26.0 milestone on Jun 23, 2026
  5. added a commit that references this issue on Jun 23, 2026
    68a7f83
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-negative

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions