Skip to content

[java] UselessOverridingMethod: False negative when super call is wrapped in nested blocks #6491

@leemeii

Description

@leemeii

Affects PMD Version: 7.20.0

Rule:UselessOverridingMethod

Description:
The rule UselessOverridingMethod fails to detect redundant overrides when the super call is wrapped inside an additional nested block (braces {}).

Code Sample demonstrating the issue:

public class UselessOverrideBug {

    // Scenario A: Standard useless override (PMD reports this correctly)
    public static class ClassA {
        @Override
        public String toString() {
            return super.toString();
        }
    }

    // Scenario B: Useless override wrapped in nested blocks (FN - PMD misses this)
    public static class ClassB {
        @Override
        public String toString() {
            { // Extra block level 1
              return super.toString();   
            }
        }
    }
}

Expected outcome:
PMD should report a violation for both ClassA and ClassB at their respective toString method declarations, as both methods do nothing but call the superclass implementation.This is a false-negative.

Running PMD through: CLI

Metadata

Metadata

Assignees

No one assigned

    Labels

    a:false-negativePMD doesn't flag a problematic piece of code

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions