Affects PMD Version: Since 6.2.0, when the rule was introduced
Rule: MissingOverride
Description: There are 2 long-standing issues with MissingOverride, related to overriding of a method using type parameters of a parameterized supertype. This is caused by its implementation strategy, since it counts bridge methods in a Class file.
The issue is described at length around this line:
|
// This is a good heuristic, though not perfect. |
There are already regression tests in the test file:
|
<test-code> |
|
<description>Avoid false positives when in ambiguous situation</description> |
|
<expected-problems>0</expected-problems> |
|
<code><![CDATA[ |
|
package net.sourceforge.pmd.lang.java.rule.bestpractices.missingoverride; |
|
|
|
import java.util.Comparator; |
|
|
|
|
|
public class AmbiguousOverload implements Comparator<StringBuilder> { |
|
|
|
// only one of those overloads is an override, and so there's only one bridge, |
|
// so we can't choose the inherited overload |
|
|
|
// missing |
|
public int compare(StringBuilder o1, StringBuilder o2) { |
|
return 0; |
|
} |
|
|
|
public int compare(String s, String s2) { |
|
return 0; |
|
} |
|
} |
|
]]></code> |
|
</test-code> |
|
|
|
<test-code> |
|
<description>Avoid false positives when in ambiguous situation</description> |
|
<expected-problems>0</expected-problems> |
|
<code><![CDATA[ |
|
package net.sourceforge.pmd.lang.java.rule.bestpractices.missingoverride; |
|
|
|
import net.sourceforge.pmd.lang.ast.Node; |
|
import net.sourceforge.pmd.lang.java.ast.ASTType; |
|
import net.sourceforge.pmd.lang.java.ast.AbstractJavaTypeNode; |
|
import net.sourceforge.pmd.lang.java.ast.JavaNode; |
|
|
|
public abstract class HierarchyWithSeveralBridges<T extends Node> { |
|
|
|
abstract void foo(T node); |
|
|
|
public static abstract class SubclassOne<T extends JavaNode> extends HierarchyWithSeveralBridges<T> { |
|
|
|
// this one could be resolved |
|
// @Override |
|
// abstract void foo(T node); |
|
|
|
} |
|
|
|
public static abstract class SubclassTwo<T extends AbstractJavaTypeNode> extends SubclassOne<T> { |
|
|
|
} |
|
|
|
|
|
public static class Concrete extends SubclassTwo<ASTType> { |
|
|
|
// bridges: foo(AbstractJavaTypeNode), foo(JavaNode), foo(Node) |
|
|
|
// missing |
|
void foo(ASTType node) { |
|
|
|
} |
|
} |
|
} |
|
]]></code> |
|
</test-code> |
This may be fixed easily in PMD 7, since we don't use Class files and have all necessary utilities to test for overriding in TypeOps already:
|
public static boolean overrides(JMethodSig m1, JMethodSig m2, JTypeMirror origin) { |
|
public static boolean areOverrideEquivalent(JMethodSig m1, JMethodSig m2) { |
Expected outcome:
PMD should report violations for the two test cases, this is a false negative
Affects PMD Version: Since 6.2.0, when the rule was introduced
Rule: MissingOverride
Description: There are 2 long-standing issues with MissingOverride, related to overriding of a method using type parameters of a parameterized supertype. This is caused by its implementation strategy, since it counts bridge methods in a Class file.
The issue is described at length around this line:
pmd/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/MissingOverrideRule.java
Line 286 in 59f1fe2
There are already regression tests in the test file:
pmd/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/bestpractices/xml/MissingOverride.xml
Lines 379 to 444 in 59f1fe2
This may be fixed easily in PMD 7, since we don't use Class files and have all necessary utilities to test for overriding in TypeOps already:
pmd/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/TypeOps.java
Line 1317 in 1b13771
pmd/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/TypeOps.java
Line 1213 in 1b13771
Expected outcome:
PMD should report violations for the two test cases, this is a false negative