GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — [apex] UnusedLocalVariable false positive in dynamic SOQL · Issue #2669 · pmd/pmd Closed Labels a:false-positivePMD flags a piece of code that is not problematic Milestone DescriptionAffects PMD Version: 6.26.0 and 6.29.0 Rule: Description: Local variables marked as unused despite references in dynamic SOQL queries (strings). See also Dynamic SOQL Code Sample demonstrating the issue: public class MyClass implements Database.Batchable<sObject> { public Database.QueryLocator start(Database.BatchableContext bc) { Date todayDate = System.today(); String recordTypeName = 'MyRecordType'; String query = 'SELECT Id FROM Account WHERE RecordType.DeveloperName = :recordTypeName'; if (lastRunOn == null) { query += ' AND createdDate < :todayDate'; } return Database.getQueryLocator(query); } } {
"formatVersion": 0,
"pmdVersion": "6.26.0",
"timestamp": "2020-07-27T13:16:06.532+01:00",
"files": [
{
"filename": "MyClass.cls",
"violations": [
{
"beginline": 3,
"begincolumn": 14,
"endline": 3,
"endcolumn": 22,
"description": "Variable \u0027todayDate\u0027 defined but not used",
"rule": "UnusedLocalVariable",
"ruleset": "Best Practices",
"priority": 1,
"externalInfoUrl": "${pmd.website.baseurl}/pmd_rules_apex_bestpractices.html#unusedlocalvariable"
},
{
"beginline": 4,
"begincolumn": 16,
"endline": 4,
"endcolumn": 29,
"description": "Variable \u0027recordTypeName\u0027 defined but not used",
"rule": "UnusedLocalVariable",
"ruleset": "Best Practices",
"priority": 1,
"externalInfoUrl": "${pmd.website.baseurl}/pmd_rules_apex_bestpractices.html#unusedlocalvariable"
}
]
}
],
"suppressedViolations": [],
"processingErrors": [],
"configurationErrors": []
}Expected outcome: This is a false positive since the local variables are referenced inside the query strings. I expect no violation reported. Running PMD through: Ant Activity
MetadataMetadataAssigneesLabelsa:false-positivePMD flags a piece of code that is not problematic TypeProjectsMilestoneRelationshipsDevelopmentIssue actions |
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |