Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[apex] ApexCRUDViolationRule not reporting for Database.query #2628

Open
wollamshram opened this issue Jul 2, 2020 · 3 comments
Open

[apex] ApexCRUDViolationRule not reporting for Database.query #2628

wollamshram opened this issue Jul 2, 2020 · 3 comments
Labels
a:false-negative PMD doesn't flag a problematic piece of code

Comments

@wollamshram
Copy link

wollamshram commented Jul 2, 2020

Affects PMD 7.0.0

Rule: ApexCRUDViolation

Description:

The ApexCRUDViolation rule does not report on potential CRUD violations if they are using the Database library to perform queries or DML, for example: Contact c = Database.query('SELECT Name FROM Contact');

The following methods are not yet considered by this rule:

  • Database.countQuery(String query)
  • Database.getQueryLocator(String query)
  • Database.query(String queryString)

See https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_database.htm for full API doc.

@oowekyala oowekyala changed the title ApexCRUDViolationRule not reporting on operations which use Database library [apex] ApexCRUDViolationRule not reporting on operations which use Database library Jul 4, 2020
@oowekyala oowekyala added the a:false-positive PMD flags a piece of code that is not problematic label Jul 4, 2020
@adangel adangel added a:false-negative PMD doesn't flag a problematic piece of code and removed a:false-positive PMD flags a piece of code that is not problematic labels Jul 2, 2021
@adangel adangel changed the title [apex] ApexCRUDViolationRule not reporting on operations which use Database library [apex] ApexCRUDViolationRule not reporting Database.query Dec 16, 2022
@adangel adangel changed the title [apex] ApexCRUDViolationRule not reporting Database.query [apex] ApexCRUDViolationRule not reporting for Database.query Dec 16, 2022
@nwcm
Copy link
Contributor

nwcm commented Apr 30, 2023

Will confirm this issue still exists in 7.0.0-rc2

If someone can point me in a direction i can attempt to resolve

@jsotuyod
Copy link
Member

Thanks for volunteering. I'm happy to give you some pointers.

This is the switch were different Database method calls are checked:

switch (node.getMethodName().toLowerCase(Locale.ROOT)) {
case "insert":
case "insertasync":
case "insertimmediate":
checkForCRUD(node, data, IS_CREATEABLE);
break;
case "update":
case "updateasync":
case "updateimmediate":
checkForCRUD(node, data, IS_UPDATEABLE);
break;
case "delete":
case "deleteasync":
case "deleteimmediate":
checkForCRUD(node, data, IS_DELETABLE);
break;
case "undelete":
checkForCRUD(node, data, IS_UNDELETABLE);
break;
case "upsert":
checkForCRUD(node, data, IS_CREATEABLE);
checkForCRUD(node, data, IS_UPDATEABLE);
break;
case "merge":
checkForCRUD(node, data, IS_MERGEABLE);
break;
default:
break;
}

You would have to add the cases for those methods and check the type of operation. As these are read only methods, all checks should be as IS_ACCESSIBLE.

The add proper test cases. You can follow this PR as a general guide #3201

For what I see in the documentation you linked though, there are plenty more methods still unmaped.

@nwcm
Copy link
Contributor

nwcm commented Apr 30, 2023

Thanks for the pointer, i'll take a look.

Another issue seems to be it ignores these methods when the class has the namespace. I would assume this is handled in the node traversal somehow

image

@jsotuyod jsotuyod added the needs:pmd7-revalidation The issue hasn't yet been retested vs PMD 7 and may be stale label Mar 17, 2024
@jsotuyod jsotuyod removed the needs:pmd7-revalidation The issue hasn't yet been retested vs PMD 7 and may be stale label Apr 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:false-negative PMD doesn't flag a problematic piece of code
Projects
None yet
Development

No branches or pull requests

5 participants