pmd: fix #991 AvoidSynchronizedAtMethodLevel for static methods

This commit is contained in:
Andreas Dangel 2013-08-03 13:08:26 +02:00
parent da1ee1fe72
commit eb57fdc882
3 changed files with 39 additions and 2 deletions

View File

@ -1,5 +1,6 @@
????? ??, 2013 - 5.0.5:
Fixed bug 991: AvoidSynchronizedAtMethodLevel for static methods
Fixed bug 1114: CPD - Tokenizer not initialized with requested properties

View File

@ -866,13 +866,23 @@ gets it.
<example>
<![CDATA[
public class Foo {
// Try to avoid this
// Try to avoid this:
synchronized void foo() {
}
// Prefer this:
void bar() {
synchronized(this) {
}
}
}
// Try to avoid this for static methods:
static synchronized void fooStatic() {
}
// Prefer this:
static void barStatic() {
synchronized(Foo.class) {
}
}
}
]]>

View File

@ -24,4 +24,30 @@ public class Foo {
}
]]></code>
</test-code>
<test-code>
<description>#991 AvoidSynchronizedAtMethodLevel for static methods - bad case</description>
<expected-problems>1</expected-problems>
<code><![CDATA[
public class Test {
public static synchronized void foo() {
// complete method is synchronized on Test.class
}
}
]]></code>
</test-code>
<test-code>
<description>#991 AvoidSynchronizedAtMethodLevel for static methods - good case</description>
<expected-problems>0</expected-problems>
<code><![CDATA[
public class Test {
public static void foo() {
synchronized(Test.class) {
// only a block is synchronized on Test.class
}
}
}
]]></code>
</test-code>
</test-data>