Skip to content

[java] MissingOverride false-positive triggered by package-private method overwritten in another package by extending class.  #1969

@linusjf

Description

@linusjf

Affects PMD Version:
6.16.0, 6.17.0

Rule:
MissingOverride

Description:
False positive for package-private method triggered by class extended in another package.
A package-private method cannot
be directly overridden by a method in a different package JLS 8.4.8.1.
The method in the derived class is not the inherited method and thus the rule should not flag it as needing an @OverRide annotation. Package-private methods can only be overridden by classes defined in the same package as the base class.

Code Sample demonstrating the issue:

package click;
public class CodeTalk {
    public void doIt() {
        printMessage();
    }
    void printMessage() {
        System.out.println("Click");
    }
}

package hack;
import click.CodeTalk;
public class TypeIt {
    private static class ClickIt extends CodeTalk {
        void printMessage() {
            System.out.println("Hack");
        }
    }

    public static void main(String[] args) {
        ClickIt clickit = new ClickIt();
        clickit.doIt();
    }
}

Running PMD through: *[CLI | Ant] *

Metadata

Metadata

Assignees

Labels

a:false-positivePMD flags a piece of code that is not problematic

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions