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] ApexCRUDViolation does not recognise Lists declarated with array syntax #4993

Open
jh480 opened this issue May 3, 2024 · 0 comments
Labels
a:false-positive PMD flags a piece of code that is not problematic

Comments

@jh480
Copy link

jh480 commented May 3, 2024

Affects PMD Version:
7.0.0

Rule:
https://docs.pmd-code.org/latest/pmd_rules_apex_security.html#ApexCRUDViolationRule

Description: Code below only validates list variables declared with List<[..]> , but Apex also allows array syntax for their List class.

Code Sample demonstrating the issue:

    public void foo() {
        Contact[] contacts = new List<Contact>();

        contacts.add(new Contact());

        if (Contact.sObjectType.getDescribe(SObjectDescribeOptions.DEFERRED).isCreateable()) {
            insert contacts;
        }
    }

Expected outcome:

PMD reports a violation at line 7, but that's wrong. That's a false positive.

Running PMD through: Apex PMD (VSC)

@jh480 jh480 added the a:false-positive PMD flags a piece of code that is not problematic label May 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:false-positive PMD flags a piece of code that is not problematic
Projects
None yet
Development

No branches or pull requests

1 participant