pmd: fix #991 AvoidSynchronizedAtMethodLevel for static methods
This commit is contained in:
parent
da1ee1fe72
commit
eb57fdc882
@ -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
|
||||
|
||||
|
||||
|
@ -866,7 +866,7 @@ gets it.
|
||||
<example>
|
||||
<![CDATA[
|
||||
public class Foo {
|
||||
// Try to avoid this
|
||||
// Try to avoid this:
|
||||
synchronized void foo() {
|
||||
}
|
||||
// Prefer this:
|
||||
@ -874,6 +874,16 @@ public class Foo {
|
||||
synchronized(this) {
|
||||
}
|
||||
}
|
||||
|
||||
// Try to avoid this for static methods:
|
||||
static synchronized void fooStatic() {
|
||||
}
|
||||
|
||||
// Prefer this:
|
||||
static void barStatic() {
|
||||
synchronized(Foo.class) {
|
||||
}
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
|
@ -21,6 +21,32 @@ public class Foo {
|
||||
void foo () {
|
||||
synchronized(mutex) {}
|
||||
}
|
||||
}
|
||||
]]></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>
|
||||
|
Loading…
x
Reference in New Issue
Block a user