Apply suggestions from code review

This commit is contained in:
Andreas Dangel
2024-08-29 12:41:02 +02:00
committed by GitHub
parent 8a39917fa2
commit 93db59bea5
2 changed files with 15 additions and 4 deletions

View File

@ -30,7 +30,7 @@ needs mutual exclusion will be locked.
<![CDATA[
public class Foo {
// Try to avoid this:
synchronized void bar() {
synchronized void foo() {
// code, that doesn't need synchronization
// ...
// code, that requires synchronization
@ -63,7 +63,7 @@ public class Foo {
}
// Prefer this:
private static Lock CLS_LOCK = new ReentrantLock();
private static Lock CLASS_LOCK = new ReentrantLock();
static void barStatic() {
// code, that doesn't need synchronization

View File

@ -5,7 +5,7 @@
xsi:schemaLocation="http://pmd.sourceforge.net/rule-tests http://pmd.sourceforge.net/rule-tests_1_0_0.xsd">
<test-code>
<description>TEST1</description>
<description>Synchronized block in instance method</description>
<expected-problems>1</expected-problems>
<code><![CDATA[
public class Foo {
@ -17,7 +17,7 @@ public class Foo {
</test-code>
<test-code>
<description>#991 AvoidSynchronizedStatement for static methods</description>
<description>Synchronized block in static methods</description>
<expected-problems>1</expected-problems>
<code><![CDATA[
public class Test {
@ -26,6 +26,17 @@ public class Test {
// only a block is synchronized on Test.class
}
}
}
]]></code>
</test-code>
<test-code>
<description>synchronized methods are not flagged - we have a separate rule AvoidSynchronizedAtMethodLevel for that</description>
<expected-problems>0</expected-problems>
<code><![CDATA[
public class Test {
public synchronized void foo() {}
public static synchronized void fooStatic() {}
}
]]></code>
</test-code>