You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Description: When you write your SOQL on multiple lines and running the cpd command, it will log false positive of duplicate code.
Code Sample demonstrating the issue:
List<Account> accountList = [
SELECT
Id,
Name,
Site
FROM
Account
WHERE
Id IN :myIdList
];
List<Account> accountList2 = [
SELECT
Id,
Name,
Site
FROM
Account
WHERE
CreatedDate < TODAY
];
Running PMD through: cmd
PMD Result:
Found a 8 line (x tokens) duplication in the following files:
Starting at line 2 of myFile.cls
Starting at line 12 of myFile.cls
List<Account> accountList2 = [
SELECT
Id,
Name,
Site
FROM
Account
WHERE
NB: if you run my example as it is, you won't get my result because I minimized the number of selected fields for the example. I think it shouldn't evaluate each line but the SOQL as a whole.
And also my code is totally stupid and only made for the example (if you wonder why).
Interesting... we are using the ApexLexer from jorje, so they are the ones splitting the SOQL into tokens... we may rebuild it as a single "token" for the whole SOQL on top of that, but we'd have to evaluate if this approach doesn't introduce any unwanted byproducts...
Activity
jsotuyod commentedon Jan 10, 2018
Interesting... we are using the
ApexLexerfrom jorje, so they are the ones splitting the SOQL into tokens... we may rebuild it as a single "token" for the whole SOQL on top of that, but we'd have to evaluate if this approach doesn't introduce any unwanted byproducts...adangel commentedon Jan 29, 2026
Can still be reproduced with 7.21.0.