pmd / pmd

An extensible multilanguage static code analyzer.
https://pmd.github.io
Other
4.79k stars 1.48k forks source link

[apex] ApexCRUDViolation not checking queries when used as map constructor arguments #3419

Open jonathanwiesel opened 3 years ago

jonathanwiesel commented 3 years ago

Affects PMD Version: 5.5.3+ 6.0.0+ 7.0.0

Rule:

ApexCRUDViolation

Description:

When a query is issued inside a map constructor the CRUD check is not enforced

Code Sample demonstrating the issue:

public class Foo {
  public void bar() {
    Map<Id, Account> accs = new Map<Id, Account>([SELECT Name FROM Account]);
  }
}

Expected outcome:

PMD should report a violation at line 3, but doesn't. This is a false-negative.

Running PMD through: Apex PMD VS Code Plugin

jonathanwiesel commented 3 years ago

Related to #3378 due to the difficulty of determining the appropriate type to check on maps