JavaScript is not currently enabled, but is required for full CodeSonar manual search and browse functionality.
If you are viewing this file in your hub's Web GUI, enable JavaScript in your browser: you will also need it for GUI functionality.
If you opened this file directly from disk, your browser may be directly suppressing JavaScript functionality: certain browsers perform this suppression on local files (but not files delivered by web servers) for security reasons.
| CodeSonar® 9.2p0 | CONFIDENTIAL | CodeSecure Inc |
An implements clause is already present and could be removed.
Java classes can be extended and methods overridden. Sometimes, it is possible that methods are redefined in a way that seems an overriding but is actually the definition of another, distinct method. This is often cause of ambiguities and bugs. Moreover, fields in Java cannot be overridden and a subclass may add a synonym field of a superclass: the class ends up having two fields with the same name. This is often a source of ambiguities and might lead programmers to think that the field is actually overridden at all uses, while distinct synonym fields are used at different program points. This checker finds ambiguities and bugs in the extension of classes, method overriding and fields redefinition.
| Class Name | Redundant Implements Clause (Java) | |||
|---|---|---|---|---|
| Significance | reliability | |||
| Mnemonic | JAVA.CLASS.RI | |||
| Categories |
|
|||
| Availability | Available for Java and Kotlin. |
|||
| Enabling | Checks for this warning class are enabled by
default. To disable them, add the following WARNING_FILTER rule to the
project configuration file.
WARNING_FILTER += discard class="Redundant Implements Clause (Java)" |
The following example code uses two different classes named C (neither is shown):
// Super.java
import sub.C;
public class Super implements Cloneable {
public final int k = 13;
public Super() {}
public float myMethod(int a, float f) {
return a + f + k;
}
public void anotherMethod(C par) {}
}
// Sub1.java public class Sub1 extends Super implements Cloneable { // Redundant Implements Clause (Java) warning issued here public Sub1() {} public float myMethod(int a, int f) { return a + f; } }
// Sub2.java public class Sub2 extends Super { public Sub2() {} public float mymethod(int a, float f) { // Method Names Differ Only in Case (Java) warning issued here return a + f; } }
// Sub3.java public class Sub3 extends Super { public final int k = 17; // Shadowed Identifier (Java) warning issued here public Sub3() {} public void anotherMethod(C par) {} // Non-overriding Method Signature (Java) warning issued here }
In this example, the programmer would probably rewrite the classes as follows.
// Super.java after rewriting
import sub.C;
public class Super implements Cloneable {
public final int k = 13;
public Super() {}
public float myMethod(int a, float f) {
return a + f + k;
}
public void anotherMethod(C par) {}
}
// Sub1.java after rewriting
public class Sub1 extends Super {
public Sub1() {}
public float myMethod(int a, int f) {
return a + f;
}
}
// Sub2.java after rewriting
public class Sub2 extends Super {
public Sub2() {}
public float myMethod(int a, float f) {
return a + f;
}
}
// Sub3.java after rewriting
public class Sub3 extends Super {
public Sub3() {}
public void anotherMethod(sub.C par) {}
}
Check if a method redefinition should rather be an overriding. Check if a synonym field, already defined in a superclass, should be removed or renamed.
The following configuration file parameters affect checks for this warning class.
To report problems with this documentation, please visit https://support.codesecure.com/.