Skip to content

[apex] Report SOQL injection violations at query calls - #7268

Open
Gabrieljr42 wants to merge 1 commit into
pmd:mainfrom
Gabrieljr42:fix/apex-soql-injection-location-5734
Open

Gabrieljr42 wants to merge 1 commit into
pmd:mainfrom
Gabrieljr42:fix/apex-soql-injection-location-5734

Conversation

@Gabrieljr42

Copy link
Copy Markdown
Contributor

Describe the PR

ApexSOQLInjection currently reports an unsafe variable inside a query, so a multiline query can be reported on its last line. Report both concatenated queries and query variables at the matching Database.query or Database.countQuery call instead. The detection conditions and number of violations are preserved.

Adds regression cases for the original wrapped multiline query, multiline countQuery with multiple unsafe variables, query arguments on later lines, single-line queries, and sanitized queries. Also adds the fixed-issue release note.

Related issues

Validation

  • Reproduced on current main (e08cc0e): the new cases produced three expected location failures; the original example reported line 6 instead of line 3.
  • ./mvnw -pl pmd-apex -am -Dtest=ApexSOQLInjectionTest -Dsurefire.failIfNoSpecifiedTests=false test: 59 tests passed.
  • ./mvnw -pl pmd-apex -am verify: passed on JDK 25, including Checkstyle, API compatibility, and documentation generation. 7,946 tests run, no failures or errors, 9 skipped.

Ready?

  • Added unit tests for fixed bug/feature
  • Passing all unit tests in the Apex reactor
  • Complete build ./mvnw clean verify passes (checked automatically by GitHub Actions)
  • Added release note

I used AI assistance for the implementation and tests.

@Gabrieljr42
Gabrieljr42 marked this pull request as ready for review October 31, 2026 00:06
@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, 25 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-10-31 00:22:37+00:00 for 6c7dcca)

This branch has not been deployed

No deployments
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] PMD for Salesforce: multi-line statement fragment inclusion in the report is unsatisfactory and inconsistent

1 participant