diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/security/ApexCRUDViolationRule.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/security/ApexCRUDViolationRule.java index c0d7a9511b..ffd19bcbac 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/security/ApexCRUDViolationRule.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/security/ApexCRUDViolationRule.java @@ -30,6 +30,7 @@ import net.sourceforge.pmd.lang.apex.ast.ASTIfElseBlockStatement; import net.sourceforge.pmd.lang.apex.ast.ASTMethod; import net.sourceforge.pmd.lang.apex.ast.ASTMethodCallExpression; import net.sourceforge.pmd.lang.apex.ast.ASTNewNameValueObjectExpression; +import net.sourceforge.pmd.lang.apex.ast.ASTParameter; import net.sourceforge.pmd.lang.apex.ast.ASTProperty; import net.sourceforge.pmd.lang.apex.ast.ASTReferenceExpression; import net.sourceforge.pmd.lang.apex.ast.ASTReturnStatement; @@ -522,7 +523,8 @@ public class ApexCRUDViolationRule extends AbstractApexRule { final boolean startsWithGet = method.getNode().getMethodInfo().getCanonicalName().startsWith("get"); final boolean voidOrString = VOID_OR_STRING_PATTERN .matcher(method.getNode().getMethodInfo().getEmitSignature().getReturnType().getApexName()).matches(); + final boolean noParams = method.findChildrenOfType(ASTParameter.class).isEmpty(); - return (startsWithGet && !voidOrString); + return (startsWithGet && noParams && !voidOrString); } } diff --git a/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/security/xml/ApexCRUDViolation.xml b/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/security/xml/ApexCRUDViolation.xml index 8ced37f6d1..cf86fcb547 100644 --- a/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/security/xml/ApexCRUDViolation.xml +++ b/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/security/xml/ApexCRUDViolation.xml @@ -1,7 +1,21 @@ - + + + Not a getter + 1 + + + Proper CRUD,FLS via upsert 0 @@ -468,8 +482,8 @@ public class Foo { } ]]> - - + + No issues found in test classes 0 - + Control flow based CRUD,FLS check 0 @@ -499,7 +513,7 @@ public class Foo { } } ]]> - + Control flow based CRUD,FLS check recursive 0 @@ -523,8 +537,9 @@ public class Foo { } ]]> - - Control flow constructor based CRUD,FLS check + + Control flow constructor based CRUD,FLS check + 0 - - + + Control flow accessibility CRUD check 0 @@ -562,8 +577,8 @@ public class Foo { } } ]]> - - + + Control flow substitute CRUD check 0 @@ -583,7 +598,7 @@ public class Foo { } ]]> - + Forgot to call the CRUD check 1 @@ -603,7 +618,8 @@ public class Foo { ]]> - Control flow substitute CRUD check should fail when check follows SOQL + Control flow substitute CRUD check should fail when check + follows SOQL 1 - + Control flow with nested statementsL @@ -643,6 +659,6 @@ public class Foo { } ]]> - +