diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index 8abb75f161..a03242a8f0 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -25,5 +25,8 @@ This is a {{ site.pmd.release_type }} release. ### External Contributions +* [#2448](https://github.com/pmd/pmd/pull/2448): \[java] Operator Wrap check - [Harsh Kukreja](https://github.com/harsh-kukreja) + + {% endtocmaker %} diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/bestpractices/AvoidGlobalModifierRule.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/bestpractices/AvoidGlobalModifierRule.java index ed12d54d1b..f01b49bfee 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/bestpractices/AvoidGlobalModifierRule.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/bestpractices/AvoidGlobalModifierRule.java @@ -33,6 +33,10 @@ public class AvoidGlobalModifierRule extends AbstractApexRule { addViolation(data, node); } + // Note, the rule reports the whole class, since that's enough and stops to visit right here. + // It also doesn't use rulechain, since it the top level type needs to global. + // if a member is global, that class has to be global as well to be valid apex. + // See also https://github.com/pmd/pmd/issues/2298 return data; } diff --git a/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/bestpractices/xml/AvoidGlobalModifier.xml b/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/bestpractices/xml/AvoidGlobalModifier.xml index 470fbdee69..a182455e52 100644 --- a/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/bestpractices/xml/AvoidGlobalModifier.xml +++ b/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/bestpractices/xml/AvoidGlobalModifier.xml @@ -28,26 +28,32 @@ global interface Foo { Global method 1 + 1 - + ]]> + Global inner interface 1 + 1 - + ]]> + #1348 [apex] AvoidGlobalModifierRule gives warning even when its a REST webservice - false positive diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTArguments.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTArguments.java index 7739488082..0204618248 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTArguments.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTArguments.java @@ -5,6 +5,7 @@ package net.sourceforge.pmd.lang.java.ast; import net.sourceforge.pmd.annotation.InternalApi; +import net.sourceforge.pmd.lang.ast.xpath.internal.DeprecatedAttribute; public class ASTArguments extends AbstractJavaNode { @@ -29,6 +30,7 @@ public class ASTArguments extends AbstractJavaNode { * @deprecated for removal. Use {@link #size()} or {@link ASTArgumentList#size()} instead. */ @Deprecated + @DeprecatedAttribute(replaceWith = "@Size") public int getArgumentCount() { return size(); } diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTConstructorDeclaration.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTConstructorDeclaration.java index 628e5f57f8..086047c941 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTConstructorDeclaration.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTConstructorDeclaration.java @@ -6,6 +6,7 @@ package net.sourceforge.pmd.lang.java.ast; import net.sourceforge.pmd.annotation.InternalApi; +import net.sourceforge.pmd.lang.ast.xpath.internal.DeprecatedAttribute; public class ASTConstructorDeclaration extends AbstractMethodOrConstructorDeclaration { @@ -57,6 +58,7 @@ public class ASTConstructorDeclaration extends AbstractMethodOrConstructorDeclar * @deprecated Use {@link #getArity()} */ @Deprecated + @DeprecatedAttribute(replaceWith = "@Arity") public int getParameterCount() { return getArity(); } diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTFieldDeclaration.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTFieldDeclaration.java index d91fbaf9aa..13a23aa3ea 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTFieldDeclaration.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTFieldDeclaration.java @@ -8,6 +8,7 @@ import java.util.Iterator; import net.sourceforge.pmd.annotation.InternalApi; import net.sourceforge.pmd.lang.ast.SignedNode; +import net.sourceforge.pmd.lang.ast.xpath.internal.DeprecatedAttribute; import net.sourceforge.pmd.lang.java.multifile.signature.JavaFieldSignature; import net.sourceforge.pmd.lang.java.typeresolution.typedefinition.JavaTypeDefinition; @@ -178,6 +179,7 @@ public class ASTFieldDeclaration extends AbstractJavaAccessTypeNode implements D * Iterate on the {@linkplain ASTVariableDeclaratorId VariableDeclaratorIds} instead */ @Deprecated + @DeprecatedAttribute(replaceWith = "VariableDeclaratorId/@Name") public String getVariableName() { ASTVariableDeclaratorId decl = getFirstDescendantOfType(ASTVariableDeclaratorId.class); if (decl != null) { diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTFormalParameters.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTFormalParameters.java index 2a4d213924..e684955e66 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTFormalParameters.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTFormalParameters.java @@ -7,6 +7,8 @@ package net.sourceforge.pmd.lang.java.ast; import java.util.Iterator; import java.util.List; +import net.sourceforge.pmd.lang.ast.xpath.internal.DeprecatedAttribute; + public class ASTFormalParameters extends AbstractJavaNode implements Iterable { @@ -24,6 +26,7 @@ public class ASTFormalParameters extends AbstractJavaNode implements Iterable 0; } diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/CloneMethodMustImplementCloneableRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/CloneMethodMustImplementCloneableRule.java index 0566a1ee45..495e9bf31c 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/CloneMethodMustImplementCloneableRule.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/CloneMethodMustImplementCloneableRule.java @@ -91,8 +91,8 @@ public class CloneMethodMustImplementCloneableRule extends AbstractJavaRule { // Is the clone method just throwing CloneNotSupportedException? final ASTClassOrInterfaceDeclaration classOrInterface = node.getFirstParentOfType(ASTClassOrInterfaceDeclaration.class); - if (classOrInterface != null && //Don't analyze enums, which cannot subclass clone() - (node.isFinal() || classOrInterface.isFinal())) { + if (classOrInterface != null //Don't analyze enums, which cannot subclass clone() + && (node.isFinal() || classOrInterface.isFinal())) { if (node.findDescendantsOfType(ASTBlock.class).size() == 1) { final List blocks = node.findDescendantsOfType(ASTBlockStatement.class); if (blocks.size() == 1) {