Affects PMD Version:
6.27.0
Description:
ApexSharingViolations scans inner and outer classes for DML, SOQL, or SOSL. The rule only looks at the outer class for a sharing declaration. As described here the sharing setting applies to the class that performs the data access.
Both inner classes and outer classes can be declared as with sharing. The sharing setting applies to all code contained in the class, including initialization code, constructors, and methods.
Inner classes do not inherit the sharing setting from their container class.
Code Sample demonstrating the issue:
Example False Positive(Sharing is correctly declared on Inner
class)
public class Outer {
public with sharing class Inner {
public List<Contact> getAllInnerSoqlSecrets() { return [SELECT Name FROM Contact]; }
}
}
Example False Negative(Sharing is incorrectly declared on Outer
class)
public with sharing class Outer {
public class Inner {
public List<Contact> getAllInnerSoqlSecrets() { return [SELECT Name FROM Contact]; }
}
}
Expected outcome:
The rule is generating both a false-positive and false-negative
Running PMD through: CLI
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4