forked from phoedos/pmd
Merge branch 'pr-1924'
This commit is contained in:
@ -32,6 +32,8 @@ Being based on a proper Antlr grammar, CPD can:
|
||||
* [#1898](https://github.com/pmd/pmd/issues/1898): \[doc] Incorrect code example for DoubleBraceInitialization in documentation on website
|
||||
* [#1906](https://github.com/pmd/pmd/issues/1906): \[doc] Broken link for adding own CPD languages
|
||||
* [#1909](https://github.com/pmd/pmd/issues/1909): \[doc] Sample usage example refers to deprecated ruleset "basic.xml" instead of "quickstart.xml"
|
||||
* java-multithreading
|
||||
* [#1903](https://github.com/pmd/pmd/issues/1903): \[java] UnsynchronizedStaticFormatter doesn't allow block-level synchronization when using allowMethodLevelSynchronization=true
|
||||
* xml
|
||||
* [#1666](https://github.com/pmd/pmd/issues/1666): \[xml] wrong cdata rule description and examples
|
||||
|
||||
|
@ -77,14 +77,7 @@ public class UnsynchronizedStaticFormatterRule extends AbstractJavaRule {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (getProperty(ALLOW_METHOD_LEVEL_SYNC)) {
|
||||
ASTMethodDeclaration method = n.getFirstParentOfType(ASTMethodDeclaration.class);
|
||||
if (method != null && (!method.isSynchronized() || !method.isStatic())) {
|
||||
addViolation(data, node);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
// is there a block-level synch?
|
||||
ASTSynchronizedStatement syncStatement = n.getFirstParentOfType(ASTSynchronizedStatement.class);
|
||||
if (syncStatement != null) {
|
||||
ASTExpression expression = syncStatement.getFirstChildOfType(ASTExpression.class);
|
||||
@ -95,6 +88,15 @@ public class UnsynchronizedStaticFormatterRule extends AbstractJavaRule {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// method level synch enabled and used?
|
||||
if (getProperty(ALLOW_METHOD_LEVEL_SYNC)) {
|
||||
ASTMethodDeclaration method = n.getFirstParentOfType(ASTMethodDeclaration.class);
|
||||
if (method != null && method.isSynchronized() && method.isStatic()) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
addViolation(data, n);
|
||||
}
|
||||
return data;
|
||||
|
@ -258,6 +258,24 @@ public class Foo {
|
||||
sdf.format();
|
||||
}
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
|
||||
<test-code>
|
||||
<description>#1903 - Block synch is valid even with allowMethodLevelSynchronization</description>
|
||||
<rule-property name="allowMethodLevelSynchronization">true</rule-property>
|
||||
<expected-problems>0</expected-problems>
|
||||
<code><![CDATA[
|
||||
import java.text.SimpleDateFormat;
|
||||
|
||||
public class Foo {
|
||||
private static final SimpleDateFormat sdf = new SimpleDateFormat();
|
||||
private void bar() {
|
||||
synchronized(sdf) {
|
||||
sdf.format();
|
||||
}
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
|
Reference in New Issue
Block a user