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® 27.0w | AdaCore Inc |
A method has a name identical to another in a superclass, up to capitalization.
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 | Method Names Differ Only in Case (Java) | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Significance | reliability | |||||||||
| Mnemonic | JAVA.ID.CASE.METHOD | |||||||||
| Categories |
|
|||||||||
| Availability | Available for Java only. | |||||||||
| 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="Method Names Differ Only in Case (Java)" |
// The name of this method differs from the inherited computeScore only in case, // so it silently fails to override it and creates a confusing near-twin that is // easy to call by mistake. public class MethodNameCaseClash extends ScoreCard { public int computescore(int hits, int misses) { // 'Method Names Differ Only in Case (Java)' warning issued here return hits + misses; } }
// ok: this subclass uses the exact inherited name, so it genuinely overrides. public class NormalizedScoreCard extends ScoreCard { @Override public int computeScore(int hits, int misses) { // ok: same name as the inherited method, a real override return hits + misses; } }
// A base report type with a public scoring method.
public class ScoreCard {
public int computeScore(int hits, int misses) {
return hits - misses;
}
}
To reproduce this example, analyze it with the following configuration:
JAVA_ANALYSIS_ENTRY_POINTS_MODE = ALL_METHODS
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.adacore.com/csm.