Skip to content

[apex] Fix #3877: ApexCRUDViolation false positive on Lists of Objects with getSObjectType().getDescribe()#6769

Merged
adangel merged 1 commit into
pmd:mainfrom
lukman48:fix/3877-apex-crud-violation-getsObjectType-describe
Jun 11, 2026
Merged

[apex] Fix #3877: ApexCRUDViolation false positive on Lists of Objects with getSObjectType().getDescribe()#6769
adangel merged 1 commit into
pmd:mainfrom
lukman48:fix/3877-apex-crud-violation-getsObjectType-describe

Conversation

@lukman48

@lukman48 lukman48 commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Describe the PR

Fix false positive in ApexCRUDViolation rule when using getSObjectType().getDescribe() CRUD check pattern on custom objects.

Related issue

How to review

The issue is that the existing getDescribe() handler in collectCRUDMethodLevelChecks expects the method call's reference expression to have names ending with sObjectType (e.g., Contact.sObjectType.getDescribe()). However, for CustomObject__c.getSObjectType().getDescribe(), getSObjectType() is a method call — so the reference of getDescribe() has no names, and getSObjectType() is a child of that reference expression rather than a direct child of getDescribe().

The fix adds a new else if branch that checks for this pattern by traversing the reference expression of getDescribe() to find the getSObjectType() call and extract the SObject type name.

Test cases added

  1. getSObjectType().getDescribe() with single object DML — expects 0 violations
  2. getSObjectType().getDescribe() with List DML — expects 0 violations
  3. getSObjectType().getDescribe() with wrong CRUD check — expects 1 violation

All 911 existing tests pass (0 failures).

…ects with getSObjectType().getDescribe()
@pmd-actions-helper

Copy link
Copy Markdown
Contributor

Documentation Preview

Compared to main:
This changeset changes 0 violations,
introduces 0 new violations, 0 new errors and 0 new configuration errors,
removes 0 violations, 24 errors and 9 configuration errors.
There are 0 changed duplications, 0 new duplications and 0 removed duplications.
There are 0 changed CPD errors, 0 new CPD errors and 0 removed CPD errors.

Regression Tester Report

(comment created at 2026-06-10 06:18:59+00:00 for 4d319f9)

@adangel adangel added this to the 7.26.0 milestone Jun 11, 2026

@adangel adangel left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@adangel adangel merged commit 4d319f9 into pmd:main Jun 11, 2026
13 checks passed
adangel added a commit that referenced this pull request Jun 11, 2026
adangel added a commit that referenced this pull request Jun 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[apex] ApexCRUDViolation: False positive with Lists of Objects with getSObjectType().getDescribe()

2 participants