Skip to content

[java] EmptyMethodInAbstractClassShouldBeAbstract: False positive for final empty methods #6279

@Vampire

Description

@Vampire

Affects PMD Version: 7.18.0

Rule: EmptyMethodInAbstractClassShouldBeAbstract

Description:

When overriding a method and making it final in an abstract class, this rule should not give a finding.
This is for example used to prevent a finalizer attack by overriding the finalize method and making the method final without having an implementation in the method body.

Code Sample demonstrating the issue:

package example;

public abstract class PMDTest {
    public PMDTest() {
        throw new RuntimeException();
    }

    @Override
    protected final void finalize() {
        // prevent finalizer attack
    }
}

Expected outcome:

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

Running PMD through: Gradle

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

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions