A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/pmd/pmd/issues/2797 below:

[java] MissingOverride long-standing issues · Issue #2797 · pmd/pmd · GitHub

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


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4