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,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) {
|
||||
}
|
||||
}
|
||||
}
|
||||
]]>
|
||||
|
@ -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>
|
||||
|
Loading…
x
Reference in New Issue
Block a user