Menu

#423 False +: Overriding method merely calls super

New Tickets
closed
nobody
pmd (543)
PMD
1-Blocker
Bug
2020-02-24
2006-01-26
No

I'm getting hit by "Overriding method merely calls
super" for cases like the one below. In fact, the
overriding method does noe merely call super. It also
changes the method's access specifier from protected to
public so it can be direclty invoked. This is a
significant change that should not be flagged. I would
believe this rule if I weren't changing the access
specifier but since I am, it shoudln't be caught.
probably the same thing would apply if the subclass
made the method final to prevent further overrides.

// just so we can test protected methods
private static class ExposingSerializer extends
Serializer {

    ExposingSerializer(OutputStream out, String

encoding)
throws UnsupportedEncodingException {
super(out, encoding);
}

    public void writeChild(Node node) throws

IOException {
super.writeChild(node);
}

    public void exposedWriteRaw(String text) throws

IOException {
writeRaw(text);
}

    public void exposedWriteEscaped(String text)

throws IOException {
writeEscaped(text);
}

    public void exposedWriteAttributeValue(String

text) throws IOException {
writeAttributeValue(text);
}

    public int exposeGetColumnNumber() {
        return super.getColumnNumber();
    }

}

Discussion

  • dvholten

    dvholten - 2006-02-07

    Logged In: YES
    user_id=1310018

    how about 'synchronized' in this context?

    synchronized void method() {
    super.method();
    }

     
  • Wouter Zelle

    Wouter Zelle - 2007-10-17

    Logged In: YES
    user_id=555114
    Originator: NO

    Synchronized methods weren't flagged anymore as of 2006-10-26. Detecting the differing access specifiers requires type resolution to find out the access specifier of the superclass. Currently, this is not available.

     
  • Andreas Dangel

    Andreas Dangel - 2020-02-24
     
  • Andreas Dangel

    Andreas Dangel - 2020-02-24
    • status: open --> closed
    • Module: --> PMD
    • Milestone: --> New Tickets
    • Priority: 5 --> 1-Blocker
    • Type: --> Bug
    • Affects version: -->
    • Ruleset / Rule: -->
     

Log in to post a comment.