GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

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 #1090

New issue
Copy link
New issue
Copy link
Closed
#3577
Closed
[apex] ApexCRUDViolation: checks not detected if done in another method#1090
#3577
Copy link
Labels
a:false-positivePMD flags a piece of code that is not problematic
Milestone
6.40.0

Description

@yippie
yippie
opened on May 10, 2018
Issue body actions

Affects 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

Activity

  1. jsotuyod commented on May 10, 2018

    @jsotuyod
    jsotuyod
    on May 10, 2018
    Member
    More actions

    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
  2. jsotuyod
    added
    a:false-positivePMD flags a piece of code that is not problematic
    on May 10, 2018
  3. jsotuyod
    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, 2018
  4. rsoesemann commented on May 16, 2018

    @rsoesemann
    rsoesemann
    on May 16, 2018
    Member
    More actions

    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?

  5. jsotuyod commented on May 16, 2018

    @jsotuyod
    jsotuyod
    on May 16, 2018
    Member
    More actions

    @rsoesemann I can, look me up on Gitter and we may discuss it there.

    Reacted by Robert Sösemann
  6. nagensahu commented on Nov 13, 2019

    @nagensahu
    nagensahu
    on Nov 13, 2019
    More actions

    Is there a fix/workaround for this ? We use a Utility class for CRUD checks and it gets flagged every time.

    Reacted by Alex Barnes
  7. rsoesemann commented on Nov 13, 2019

    @rsoesemann
    rsoesemann
    on Nov 13, 2019
    Member
    More actions

    @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.

  8. rsoesemann commented on Nov 14, 2019

    @rsoesemann
    rsoesemann
    on Nov 14, 2019
    Member
    More actions

    @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?

  9. nagensahu commented on Nov 15, 2019

    @nagensahu
    nagensahu
    on Nov 15, 2019
    More actions

    @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.

  10. adangel commented on Nov 15, 2019

    @adangel
    adangel
    on Nov 15, 2019
    Member
    More actions

    @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
  11. rsoesemann commented on Nov 17, 2019

    @rsoesemann
    rsoesemann
    on Nov 17, 2019
    Member
    More actions

    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.

  12. adangel
    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, 2021
  13. adangel
    added this to the 6.40.0 milestone on Oct 23, 2021
  14. adangel
    linked a pull request that will close this issue[apex] Fix for #3576 - Added new configuration properties *AuthMethodPattern and *AuthMethodTypeParamIndex to ApexCRUDViolation rule #3577on Oct 23, 2021
  15. adangel commented on Oct 23, 2021

    @adangel
    adangel
    on Oct 23, 2021
    Member
    More actions

    Fixed by #3577. Now there are a couple of properties that can be configured to find additional check methods.

  16. adangel
    closed this as completedon Oct 23, 2021
  17. adangel
    added a commit that references this issue on Oct 23, 2021

    [doc] Update release notes (#1090, #3576, #3577, #3579)

    3ef0360
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    a:false-positivePMD flags a piece of code that is not problematic

    Type

    No type

    Projects

    No projects

      Milestone

      • 6.40.0

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.