Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
linusjf opened this issue Aug 10, 2019 · 1 comment · Fixed by #2899
Assignees
Labels
a:false-positive PMD flags a piece of code that is not problematic
Milestone

Comments

@linusjf
Copy link

linusjf commented Aug 10, 2019

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] *

@oowekyala oowekyala added this to the 6.19.0 milestone Aug 14, 2019
@oowekyala oowekyala self-assigned this Aug 14, 2019
@jsotuyod jsotuyod added the a:false-positive PMD flags a piece of code that is not problematic label Aug 18, 2019
@adangel adangel removed this from the 6.19.0 milestone Oct 26, 2019
@oowekyala oowekyala added this to the 7.0.0 milestone Nov 5, 2020
oowekyala added a commit to oowekyala/pmd that referenced this issue Nov 5, 2020
Actually was fixed by pmd#2800
@oowekyala oowekyala changed the title [Java] False positive triggered by package-private method overwritten in another package by extending class. [java] MissingOverride false-positive triggered by package-private method overwritten in another package by extending class. Nov 10, 2020
@oowekyala oowekyala linked a pull request Nov 10, 2020 that will close this issue
5 tasks
@adangel
Copy link
Member

adangel commented Dec 11, 2020

Fixed via #2899 for PMD 7.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:false-positive PMD flags a piece of code that is not problematic
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants