GeezerVison is showing github.com — [apex] ApexCRUDViolation: checks not detected if done in another method · Issue #1090 · pmd/pmd
[apex] ApexCRUDViolation: checks not detected if done in another method #1090DescriptionAffects PMD Version: 6.3
Rule: ApexCRUDViolation
Description: If I have a helper class and method to do CRUD checks, the rule flags them even if checks were done.
Code Sample demonstrating the issue:
class MyClass {
void itShouldDoTheThing(SObject myObject) {
if(Utility.checkCRUD(myObject) {
update myObject; //This gets flagged as missing CRUD check
}
}
class Utility {
static Boolean checkCRUD(SObject myObject) {
return globalDescribe.get(myObject).getDescribe().isUpdatable();
}
}
Running PMD through: CLI Activityjsotuyod commented on May 10, 2018 We could have control flow analysis on PMD as long as it's same-file, we do so in Java and some Apex rules do some basic checks. Multifile is still a little out of reach for the time being. Reacted by Robert Sösemann changed the title [-][APEX] CRUD checks not detected if done in another method[/-] [+][apex] CRUD checks not detected if done in another method[/+] on May 10, 2018rsoesemann commented on May 16, 2018 By doing some debugging in the rule I can confirm that this rule indeed does flow analysis but it gets it wrong here. Why, because it does super complicated but still naive flow checks that explode in 90% of all cases.
@jsotuyod I would love to learn how to do basic flow checks in Apex. Could you show me how? jsotuyod commented on May 16, 2018 @rsoesemann I can, look me up on Gitter and we may discuss it there. Reacted by Robert Sösemann nagensahu commented on Nov 13, 2019 Is there a fix/workaround for this ? We use a Utility class for CRUD checks and it gets flagged every time. rsoesemann commented on Nov 13, 2019 @nagensahu there is no solution to this. As @jsotuyod said someone could improve the code to at least find the check in the same file but if Code is in separate files a single filer checker as PMD will never work.
I recommend to manually annotate those cases with a specific SupressWarnings.
If you need a tool that can do multi file I recommend Clayton. rsoesemann commented on Nov 14, 2019 @jsotuyod I think we should close this as a #nofix. I see no use (or myself have no time) to make the rule work with checks moved into other methods if we cant make it work with other files. Which we can't.
What do you think? nagensahu commented on Nov 15, 2019 @rsoesemann thanks. Clayton and Checkmarx are options that we're looking at.
Was wondering if we could build a simple extra rule for our project which could check for the presence of the Utility method by name as a pattern. Its not a product fix, but can something like that be done specifically for a project ? Any suggestion appreciated.
Will post this question in other forums too. Let's see if someone has already done it. adangel commented on Nov 15, 2019 @rsoesemann
I see no use (or myself have no time)
There a huge difference between these two arguments. If you think, that improving the tool is not worth it, than close it.
If you have no time, maybe someone else has time to scratch this itch. I'm not a apex developer and I'm not using this part of PMD, so it is not itching me.
So, IMHO, it boils down to this question: Would it make the PMD Apex better if this bug is fixed or not? If yes, then we should not close it. If no, that we wasted already much time discussing it. Reacted by Robert Sösemann rsoesemann commented on Nov 17, 2019 Ok I leave it open as for me fixing it 50% (for a single file) is not enough when most of the users need to 100% (for multiple files). But you are right, somebody else might want to pick it up. changed the title [-][apex] CRUD checks not detected if done in another method[/-] [+][apex] ApexCRUDViolation: checks not detected if done in another method[/+] on Oct 23, 2021adangel commented on Oct 23, 2021 Fixed by #3577. Now there are a couple of properties that can be configured to find additional check methods.
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|