Merge branch 'pr-1635'
This commit is contained in:
@@ -21,6 +21,8 @@ This is a {{ site.pmd.release_type }} release.
|
||||
* java-codestyle
|
||||
* [#1543](https://github.com/pmd/pmd/issues/1543): \[java] LinguisticNaming should ignore overriden methods
|
||||
* [#1547](https://github.com/pmd/pmd/issues/1547): \[java] AtLeastOneConstructorRule: false-positive with lombok.AllArgsConstructor
|
||||
* java-multithreading
|
||||
* [#1633](https://github.com/pmd/pmd/issues/1633): \[java] UnsynchronizedStaticFormatter reports commons lang FastDateFormat
|
||||
|
||||
### API Changes
|
||||
|
||||
@@ -29,6 +31,7 @@ This is a {{ site.pmd.release_type }} release.
|
||||
* [#1623](https://github.com/pmd/pmd/pull/1623): \[java] Fix lombok.AllArgsConstructor support - [Bobby Wertman](https://github.com/CasualSuperman)
|
||||
* [#1625](https://github.com/pmd/pmd/pull/1625): \[java] UnusedImports false positive for method parameter type in @see Javadoc - [Shubham](https://github.com/Shubham-2k17)
|
||||
* [#1628](https://github.com/pmd/pmd/pull/1628): \[java] LinguisticNaming should ignore overriden methods - [Shubham](https://github.com/Shubham-2k17)
|
||||
* [#1635](https://github.com/pmd/pmd/pull/1635): \[java] UnsynchronizedStaticFormatter reports commons lang FastDateFormat - [Shubham](https://github.com/Shubham-2k17)
|
||||
|
||||
{% endtocmaker %}
|
||||
|
||||
|
@@ -5,6 +5,8 @@
|
||||
package net.sourceforge.pmd.lang.java.rule.multithreading;
|
||||
|
||||
import java.text.Format;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import net.sourceforge.pmd.lang.ast.Node;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceType;
|
||||
@@ -27,6 +29,9 @@ import net.sourceforge.pmd.lang.symboltable.NameOccurrence;
|
||||
*/
|
||||
public class UnsynchronizedStaticFormatterRule extends AbstractJavaRule {
|
||||
private Class<?> formatterClassToCheck = Format.class;
|
||||
private static final List<String> THREAD_SAFE_FORMATTER = Arrays.asList(
|
||||
"org.apache.commons.lang3.time.FastDateFormat"
|
||||
);
|
||||
|
||||
public UnsynchronizedStaticFormatterRule() {
|
||||
addRuleChainVisit(ASTFieldDeclaration.class);
|
||||
@@ -48,6 +53,11 @@ public class UnsynchronizedStaticFormatterRule extends AbstractJavaRule {
|
||||
}
|
||||
|
||||
ASTVariableDeclaratorId var = node.getFirstDescendantOfType(ASTVariableDeclaratorId.class);
|
||||
for (String formatter: THREAD_SAFE_FORMATTER) {
|
||||
if (TypeHelper.isA(var, formatter)) {
|
||||
return data;
|
||||
}
|
||||
}
|
||||
for (NameOccurrence occ : var.getUsages()) {
|
||||
Node n = occ.getLocation();
|
||||
if (n.getFirstParentOfType(ASTSynchronizedStatement.class) != null) {
|
||||
|
@@ -132,6 +132,20 @@ public class Foo {
|
||||
void bar() {
|
||||
messageFormat.format();
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
<test-code>
|
||||
<description>#1633 [java] UnsynchronizedStaticFormatter reports commons lang FastDateFormat</description>
|
||||
<expected-problems>0</expected-problems>
|
||||
<code><![CDATA[
|
||||
import org.apache.commons.lang3.time.FastDateFormat;
|
||||
|
||||
public class Foo {
|
||||
private static final FastDateFormat FDF = FastDateFormat.getInstance("dd.MM.yyyy HH:mm:ss");
|
||||
public void format() {
|
||||
FDF.format(new Date());
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
|
Reference in New Issue
Block a user