Skip to content

Commit

Permalink
Revert previous two commits - pushed by mistake
Browse files Browse the repository at this point in the history
  • Loading branch information
oowekyala committed May 13, 2024
1 parent 11743a4 commit f1701df
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 50 deletions.
2 changes: 0 additions & 2 deletions docs/pages/release_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ Since this release, PMD will also expose any getter returning a collection of an
* [#4985](https://github.com/pmd/pmd/issues/4985): \[java] UnusedPrivateMethod false-positive / method reference in combination with custom object
* java-codestyle
* [#4930](https://github.com/pmd/pmd/issues/4930): \[java] EmptyControlStatement should not allow empty try with concise resources
* java-multithreading
* [#2368](https://github.com/pmd/pmd/issues/2368): \[java] False positive UnsynchronizedStaticFormatter in static initializer

### 🚨 API Changes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@
import java.util.Arrays;
import java.util.List;

import net.sourceforge.pmd.lang.ast.Node;
import net.sourceforge.pmd.lang.java.ast.ASTAssignableExpr.ASTNamedReferenceExpr;
import net.sourceforge.pmd.lang.java.ast.ASTClassType;
import net.sourceforge.pmd.lang.java.ast.ASTExpression;
import net.sourceforge.pmd.lang.java.ast.ASTFieldDeclaration;
import net.sourceforge.pmd.lang.java.ast.ASTInitializer;
import net.sourceforge.pmd.lang.java.ast.ASTMethodCall;
import net.sourceforge.pmd.lang.java.ast.ASTMethodDeclaration;
import net.sourceforge.pmd.lang.java.ast.ASTSynchronizedStatement;
import net.sourceforge.pmd.lang.java.ast.ASTType;
import net.sourceforge.pmd.lang.java.ast.ASTVariableId;
import net.sourceforge.pmd.lang.java.ast.JModifier;
import net.sourceforge.pmd.lang.java.ast.internal.JavaAstUtils;
Expand Down Expand Up @@ -63,13 +62,12 @@ public Object visit(ASTFieldDeclaration node, Object data) {
if (!node.hasModifiers(JModifier.STATIC)) {
return data;
}
ASTType cit = node.getTypeNode();
if (!(cit instanceof ASTClassType)
|| !TypeTestUtil.isA(formatterClassToCheck, cit)) {
ASTClassType cit = node.descendants(ASTClassType.class).first();
if (cit == null || !TypeTestUtil.isA(formatterClassToCheck, cit)) {
return data;
}

ASTVariableId var = node.getVarIds().firstOrThrow();
ASTVariableId var = node.descendants(ASTVariableId.class).first();
for (String formatter: THREAD_SAFE_FORMATTER) {
if (TypeTestUtil.isA(formatter, var)) {
return data;
Expand All @@ -85,6 +83,8 @@ public Object visit(ASTFieldDeclaration node, Object data) {
continue;
}

Node n = ref;

// is there a block-level synch?
ASTSynchronizedStatement syncStatement = ref.ancestors(ASTSynchronizedStatement.class).first();
if (syncStatement != null) {
Expand All @@ -102,12 +102,7 @@ public Object visit(ASTFieldDeclaration node, Object data) {
}
}

boolean hasStaticInit = ref.ancestors(ASTInitializer.class).any(ASTInitializer::isStatic);
if (hasStaticInit) {
continue;
}

asCtx(data).addViolation(ref);
asCtx(data).addViolation(n);
}
return data;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -629,25 +629,6 @@ class Foo1 {
}
public void bar() {}
}
]]></code>
</test-code>
<test-code>
<description>[java] ConstructorCallsOverridableMethod: false positive with lombok's @Value #4510</description>
<expected-problems>0</expected-problems>
<code><![CDATA[
import java.util.Objects;
class AbstractClause {
Language defaultLanguage;
protected AbstractClause(@NotNull final Language defaultLanguage, @NotNull final String defaultTranslation) {
add(Objects.requireNonNull(defaultLanguage), Objects.requireNonNull(defaultTranslation));
this.defaultLanguage = defaultLanguage;
}
public @NotNull final T add(@NotNull final Language language, @NotNull final String translation) {
return getThis();
}
}
]]></code>
</test-code>
</test-data>
Original file line number Diff line number Diff line change
Expand Up @@ -304,21 +304,4 @@ public class Foo {
}
]]></code>
</test-code>
<test-code>
<description> [java] False positive UnsynchronizedStaticFormatter in static initializer #2368 </description>
<expected-problems>0</expected-problems>
<code><![CDATA[
import java.text.NumberFormat;
class WithFormatter {
private static final NumberFormat formatter;
static {
formatter = NumberFormat.getInstance();
formatter.setMaximumFractionDigits(2); // FALSE POSITIVE
}
// …
}
]]></code>
</test-code>
</test-data>

0 comments on commit f1701df

Please sign in to comment.