Fixed bug in UselessOverridingMethod: false + when adding synchronization

git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@4749 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
Xavier Le Vourch
2006-10-26 18:15:30 +00:00
parent afb64b04a6
commit abb5dcd8ce
3 changed files with 19 additions and 2 deletions

View File

@ -26,6 +26,7 @@ Fixed false negatives in UseArraysAsList.
Fixed several JDK 1.5 parsing bugs.
Fixed several rules (exceptions on jdk 1.5 and jdk 1.6 source code).
Fixed array handling in AvoidReassigningParameters and UnusedFormalParameter.
Fixed bug in UselessOverridingMethod: false + when adding synchronization.
Rules can now call RuleContext.getSourceType() if they need to make different checks on JDK 1.4 and 1.5 code.
CloseResource rule now checks code without java.sql import.
ArrayIsStoredDirectly rule now checks Constructors

View File

@ -27,7 +27,9 @@ public class UselessOverridingMethodTest extends SimpleAggregatorTst {
new TestDescriptor(TEST11, "do not crash on interfaces", 0, rule),
new TestDescriptor(TEST12, "do not crash on empty returns", 0, rule),
new TestDescriptor(TEST13, "do not crash on super", 0, rule),
new TestDescriptor(TEST14, "call super with different argument 4", 0, rule)
new TestDescriptor(TEST14, "call super with different argument 4", 0, rule),
new TestDescriptor(TEST15, "adding final is OK", 0, rule),
new TestDescriptor(TEST16, "adding synchronized is OK", 0, rule),
});
}
@ -126,4 +128,18 @@ public class UselessOverridingMethodTest extends SimpleAggregatorTst {
" }" + PMD.EOL +
"}";
private static final String TEST15 =
"public class Foo extends Bar {" + PMD.EOL +
"public final String foo() {" + PMD.EOL +
" return super.foo();" + PMD.EOL +
"}" + PMD.EOL +
"}";
private static final String TEST16 =
"public class Foo extends Bar {" + PMD.EOL +
"public synchronized String foo() {" + PMD.EOL +
" return super.foo();" + PMD.EOL +
"}" + PMD.EOL +
"}";
}

View File

@ -38,7 +38,7 @@ public class UselessOverridingMethod extends AbstractRule {
// Can skip abstract methods and methods whose only purpose is to
// guarantee that the inherited method is not changed by finalizing
// them.
if (node.isAbstract() || node.isFinal() || node.isNative()) {
if (node.isAbstract() || node.isFinal() || node.isNative() || node.isSynchronized()) {
return super.visit(node, data);
}