MethodReturnsInternalArray does not work in inner classes #1738 - Fixed
This commit is contained in:
@ -6,6 +6,7 @@ package net.sourceforge.pmd.lang.java.rule.bestpractices;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.sourceforge.pmd.lang.ast.AbstractNode;
|
||||
import net.sourceforge.pmd.lang.ast.Node;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTConditionalExpression;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTEqualityExpression;
|
||||
@ -15,7 +16,6 @@ import net.sourceforge.pmd.lang.java.ast.ASTName;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTNullLiteral;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTPrimarySuffix;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTReturnStatement;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTTypeDeclaration;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTVariableDeclaratorId;
|
||||
import net.sourceforge.pmd.lang.java.rule.AbstractJavaRule;
|
||||
|
||||
@ -38,7 +38,7 @@ public abstract class AbstractSunSecureRule extends AbstractJavaRule {
|
||||
* @return <code>true</code> if there is a field in the type declaration
|
||||
* named varName, <code>false</code> in other case
|
||||
*/
|
||||
protected final boolean isField(String varName, ASTTypeDeclaration typeDeclaration) {
|
||||
protected final boolean isField(String varName, AbstractNode typeDeclaration) {
|
||||
final List<ASTFieldDeclaration> fds = typeDeclaration.findDescendantsOfType(ASTFieldDeclaration.class);
|
||||
if (fds != null) {
|
||||
for (ASTFieldDeclaration fd : fds) {
|
||||
|
@ -8,6 +8,7 @@ import java.util.List;
|
||||
|
||||
import org.jaxen.JaxenException;
|
||||
|
||||
import net.sourceforge.pmd.lang.ast.AbstractNode;
|
||||
import net.sourceforge.pmd.lang.ast.Node;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTAllocationExpression;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTArrayInitializer;
|
||||
@ -20,7 +21,6 @@ import net.sourceforge.pmd.lang.java.ast.ASTPrimaryExpression;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTPrimaryPrefix;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTPrimarySuffix;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTReturnStatement;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTTypeDeclaration;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTVariableDeclaratorId;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTVariableInitializer;
|
||||
|
||||
@ -46,7 +46,7 @@ public class MethodReturnsInternalArrayRule extends AbstractSunSecureRule {
|
||||
return data;
|
||||
}
|
||||
List<ASTReturnStatement> returns = method.findDescendantsOfType(ASTReturnStatement.class);
|
||||
ASTTypeDeclaration td = method.getFirstParentOfType(ASTTypeDeclaration.class);
|
||||
ASTClassOrInterfaceDeclaration td = method.getFirstParentOfType(ASTClassOrInterfaceDeclaration.class);
|
||||
for (ASTReturnStatement ret : returns) {
|
||||
final String vn = getReturnedVariableName(ret);
|
||||
if (!isField(vn, td)) {
|
||||
@ -111,7 +111,7 @@ public class MethodReturnsInternalArrayRule extends AbstractSunSecureRule {
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isEmptyArray(String varName, ASTTypeDeclaration typeDeclaration) {
|
||||
private boolean isEmptyArray(String varName, AbstractNode typeDeclaration) {
|
||||
final List<ASTFieldDeclaration> fds = typeDeclaration.findDescendantsOfType(ASTFieldDeclaration.class);
|
||||
if (fds != null) {
|
||||
for (ASTFieldDeclaration fd : fds) {
|
||||
|
Reference in New Issue
Block a user