pmd: fix #940 False positive on UnsynchronizedStaticDateFormatter

This commit is contained in:
Andreas Dangel 2013-03-30 14:10:11 +01:00
parent ad66153a2d
commit f51e41b05c
3 changed files with 21 additions and 0 deletions

View File

@ -1,5 +1,6 @@
????? ??, 2013 - 5.0.3:
Fixed bug 940: False positive on UnsynchronizedStaticDateFormatter
Fixed bug 942: CheckResultSet False Positive and Negative
Fixed bug 943: PreserveStackTrace false positive if a StringBuffer exists
Fixed bug 945: PMD generates RuleSets it cannot read.

View File

@ -48,6 +48,11 @@ public class UnsynchronizedStaticDateFormatterRule extends AbstractJavaRule {
if (n.getFirstParentOfType(ASTSynchronizedStatement.class) != null) {
continue;
}
// ignore usages, that don't call a method.
if (!n.getImage().contains(".")) {
continue;
}
ASTMethodDeclaration method = n.getFirstParentOfType(ASTMethodDeclaration.class);
if (method != null && !method.isSynchronized()) {
addViolation(data, n);

View File

@ -82,6 +82,21 @@ public class Foo {
void bar() {
sdf.format();
}
}
]]></code>
</test-code>
<test-code>
<description>#940 False positive on UnsynchronizedStaticDateFormatter</description>
<expected-problems>0</expected-problems>
<code><![CDATA[
public class Test {
private static final DateFormat enFormat = new SimpleDateFormat("EEEE MMMM d, yyyy 'at' hh':'mma", Locale.US);
private static final DateFormat frFormat = new SimpleDateFormat("EEEE 'le' d MMMM yyyy 'à' HH'h'mm", Locale.CANADA_FRENCH);
protected DateFormat getDateFormat() {
return getLang() == LangEnum.FR ? frFormat : enFormat;
}
}
]]></code>
</test-code>