From 4c324ca6bd4b345f4d2b4708795fcbd6d66bde84 Mon Sep 17 00:00:00 2001 From: Sergey Gorbaty Date: Tue, 24 Jan 2017 08:46:26 -0800 Subject: [PATCH 1/2] Bug fix --- .../pmd/lang/apex/rule/security/ApexSharingViolationsRule.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/security/ApexSharingViolationsRule.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/security/ApexSharingViolationsRule.java index c960c56916..df75ad0010 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/security/ApexSharingViolationsRule.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/security/ApexSharingViolationsRule.java @@ -62,7 +62,7 @@ public class ApexSharingViolationsRule extends AbstractApexRule { * @param data */ private void checkForSharingDeclaration(ApexNode node, Object data, boolean sharingFound) { - final boolean foundAnyDMLorSOQL = Helper.foundAnyDML(node) && Helper.foundAnySOQLorSOSL(node); + final boolean foundAnyDMLorSOQL = Helper.foundAnyDML(node) || Helper.foundAnySOQLorSOSL(node); if (!sharingFound && !Helper.isTestMethodOrClass(node) && foundAnyDMLorSOQL) { addViolation(data, node); } From 847821c7c5b557e42999145dd7f7e640cee6af15 Mon Sep 17 00:00:00 2001 From: Sergey Gorbaty Date: Tue, 24 Jan 2017 08:49:12 -0800 Subject: [PATCH 2/2] Adding a test --- .../security/xml/ApexSharingViolations.xml | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/security/xml/ApexSharingViolations.xml b/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/security/xml/ApexSharingViolations.xml index 4045a2661e..5755cffd65 100644 --- a/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/security/xml/ApexSharingViolations.xml +++ b/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/security/xml/ApexSharingViolations.xml @@ -13,6 +13,18 @@ public class Foo { ]]> + + Apex class without any sharing declared with SOQL + + 1 + accounts = [SELECT Id FROM Account LIMIT 1]; + } +} + ]]> + Apex class without any sharing declared with DML @@ -27,9 +39,10 @@ public class Foo { } ]]> - + - Apex class without any sharing declared with Database method + Apex class without any sharing declared with Database + method 1 - + Apex class with sharing and Database method