Skip to content

Commit f1701df

Browse files
committed
Revert previous two commits - pushed by mistake
1 parent 11743a4 commit f1701df

File tree

4 files changed

+7
-50
lines changed

4 files changed

+7
-50
lines changed

docs/pages/release_notes.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ Since this release, PMD will also expose any getter returning a collection of an
4141
* [#4985](https://github.com/pmd/pmd/issues/4985): \[java] UnusedPrivateMethod false-positive / method reference in combination with custom object
4242
* java-codestyle
4343
* [#4930](https://github.com/pmd/pmd/issues/4930): \[java] EmptyControlStatement should not allow empty try with concise resources
44-
* java-multithreading
45-
* [#2368](https://github.com/pmd/pmd/issues/2368): \[java] False positive UnsynchronizedStaticFormatter in static initializer
4644

4745
### 🚨 API Changes
4846

pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/multithreading/UnsynchronizedStaticFormatterRule.java

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,14 @@
88
import java.util.Arrays;
99
import java.util.List;
1010

11+
import net.sourceforge.pmd.lang.ast.Node;
1112
import net.sourceforge.pmd.lang.java.ast.ASTAssignableExpr.ASTNamedReferenceExpr;
1213
import net.sourceforge.pmd.lang.java.ast.ASTClassType;
1314
import net.sourceforge.pmd.lang.java.ast.ASTExpression;
1415
import net.sourceforge.pmd.lang.java.ast.ASTFieldDeclaration;
15-
import net.sourceforge.pmd.lang.java.ast.ASTInitializer;
1616
import net.sourceforge.pmd.lang.java.ast.ASTMethodCall;
1717
import net.sourceforge.pmd.lang.java.ast.ASTMethodDeclaration;
1818
import net.sourceforge.pmd.lang.java.ast.ASTSynchronizedStatement;
19-
import net.sourceforge.pmd.lang.java.ast.ASTType;
2019
import net.sourceforge.pmd.lang.java.ast.ASTVariableId;
2120
import net.sourceforge.pmd.lang.java.ast.JModifier;
2221
import net.sourceforge.pmd.lang.java.ast.internal.JavaAstUtils;
@@ -63,13 +62,12 @@ public Object visit(ASTFieldDeclaration node, Object data) {
6362
if (!node.hasModifiers(JModifier.STATIC)) {
6463
return data;
6564
}
66-
ASTType cit = node.getTypeNode();
67-
if (!(cit instanceof ASTClassType)
68-
|| !TypeTestUtil.isA(formatterClassToCheck, cit)) {
65+
ASTClassType cit = node.descendants(ASTClassType.class).first();
66+
if (cit == null || !TypeTestUtil.isA(formatterClassToCheck, cit)) {
6967
return data;
7068
}
7169

72-
ASTVariableId var = node.getVarIds().firstOrThrow();
70+
ASTVariableId var = node.descendants(ASTVariableId.class).first();
7371
for (String formatter: THREAD_SAFE_FORMATTER) {
7472
if (TypeTestUtil.isA(formatter, var)) {
7573
return data;
@@ -85,6 +83,8 @@ public Object visit(ASTFieldDeclaration node, Object data) {
8583
continue;
8684
}
8785

86+
Node n = ref;
87+
8888
// is there a block-level synch?
8989
ASTSynchronizedStatement syncStatement = ref.ancestors(ASTSynchronizedStatement.class).first();
9090
if (syncStatement != null) {
@@ -102,12 +102,7 @@ public Object visit(ASTFieldDeclaration node, Object data) {
102102
}
103103
}
104104

105-
boolean hasStaticInit = ref.ancestors(ASTInitializer.class).any(ASTInitializer::isStatic);
106-
if (hasStaticInit) {
107-
continue;
108-
}
109-
110-
asCtx(data).addViolation(ref);
105+
asCtx(data).addViolation(n);
111106
}
112107
return data;
113108
}

pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/errorprone/xml/ConstructorCallsOverridableMethod.xml

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -629,25 +629,6 @@ class Foo1 {
629629
}
630630
public void bar() {}
631631
}
632-
]]></code>
633-
</test-code>
634-
<test-code>
635-
<description>[java] ConstructorCallsOverridableMethod: false positive with lombok's @Value #4510</description>
636-
<expected-problems>0</expected-problems>
637-
<code><![CDATA[
638-
import java.util.Objects;
639-
class AbstractClause {
640-
Language defaultLanguage;
641-
protected AbstractClause(@NotNull final Language defaultLanguage, @NotNull final String defaultTranslation) {
642-
add(Objects.requireNonNull(defaultLanguage), Objects.requireNonNull(defaultTranslation));
643-
this.defaultLanguage = defaultLanguage;
644-
}
645-
646-
public @NotNull final T add(@NotNull final Language language, @NotNull final String translation) {
647-
return getThis();
648-
}
649-
}
650-
651632
]]></code>
652633
</test-code>
653634
</test-data>

pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/multithreading/xml/UnsynchronizedStaticFormatter.xml

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -304,21 +304,4 @@ public class Foo {
304304
}
305305
]]></code>
306306
</test-code>
307-
<test-code>
308-
<description> [java] False positive UnsynchronizedStaticFormatter in static initializer #2368 </description>
309-
<expected-problems>0</expected-problems>
310-
<code><![CDATA[
311-
import java.text.NumberFormat;
312-
313-
class WithFormatter {
314-
private static final NumberFormat formatter;
315-
316-
static {
317-
formatter = NumberFormat.getInstance();
318-
formatter.setMaximumFractionDigits(2); // FALSE POSITIVE
319-
}
320-
// …
321-
}
322-
]]></code>
323-
</test-code>
324307
</test-data>

0 commit comments

Comments
 (0)