pmd: fix #940 False positive on UnsynchronizedStaticDateFormatter

This commit is contained in:
Andreas Dangel committed 2013-03-30 14:10:11 +01:00
1 parent 9b7562cd23
commit ca10969400
3 files changed
+21

No files matched your search

+1
View File
@@ -15,6 +15,7 @@ New Java rule:
????? ??, 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.
@@ -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);
@@ -85,4 +85,19 @@ public class Foo {
}
]]></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>
</test-data>