Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] The Salesforce scanner throws a syntax error in an Apex class when using the GROUPING function in a SOQL query #1579

Open
ashishrajbanshi opened this issue Aug 21, 2024 · 5 comments
Labels
WaitingForFixFromPMD Waiting for PMD to fix an issue so that we can incorporate the fix into Salesforce Code Analyzer

Comments

@ashishrajbanshi
Copy link

Have you tried to resolve this issue yourself first?

Yes

Bug Description

By updating scanner from @salesforce/sfdx-scanner 3.15.0 to @salesforce/sfdx-scanner 4.3.2, we are facing syntax error when using command sf scanner run --engine pmd,retire-js --pmdconfig .pmdruleset.xml --format html --target class_name.cls -o src_pmd.html --severity-threshold 2

Method of the class:

private List<AggregateResult> getDefects(){ AggregateResult[] defects = [SELECT object NC, object Part, object Lot, SUM(Defective_Quantity__c) defectiveQuantity, GROUPING(object1) NCGroup, GROUPING(object2) PartGroup, GROUPING(object3) LotGroup FROM object4 WHERE object IN :ncsIdSet WITH SECURITY_ENFORCED GROUP BY ROLLUP(object, object, object)]; return defects; }

Screenshot:

image

Error:

``

Output / Logs

Warning: Plugin @salesforce/sfdx-scanner (4.3.2) differs from the version specified by sf (4.4.0)
Warning: The input format for array arguments has changed. Use this format: --array-flag value1 --array-flag value2 --array-flag value3
Warning: We're continually improving Salesforce Code Analyzer. Tell us what you think! Give feedback at https://research.net/r/SalesforceCA
Warning: PMD failed to evaluate against file 'D:\WORK\SQX\sqx_11\SQX_NonConformance_Fetcher.cls'. Message: ParseException: Parse exception: com.google.summit.SummitAST$ParseException: Failed to parse D:\WORK\SQX\sqx_11\SQX_NonConformance_Fetcher.cls: Syntax error at 200:48: mismatched input '(' expecting {'after', 'before', 'get', 'inherited', 'instanceof', 'set', 'sharing', 'switch', 'transient', 'trigger', 'when', 'with', 'without', 'system', 'user', 'select', 'count', 'from', 'as', 'using', 'scope', 'where', 'order', 'by', 'limit', 'and', 'or', 'not', 'avg', 'count_distinct', 'min', 'max', 'sum', 'typeof', 'end', 'then', 'like', 'in', 'includes', 'excludes', 'asc', 'desc', 'nulls', 'first', 'last', 'group', 'all', 'rows', 'view', 'having', 'rollup', 'tolabel', 'offset', 'data', 'category', 'at', 'above', 'below', 'above_or_below', 'security_enforced', 'system_mode', 'user_mode', 'reference', 'cube', 'format', 'tracking', 'viewstat', 'custom', 'standard', 'distance', 'geolocation', 'calendar_month', 'calendar_quarter', 'calendar_year', 'day_in_month', 'day_in_week', 'day_in_year', 'day_only', 'fiscal_month', 'fiscal_quarter', 'fiscal_year', 'hour_in_day', 'week_in_month', 'week_in_year', 'converttimezone', 'yesterday', 'today', 'tomorrow', 'last_week', 'this_week', 'next_week', 'last_month', 'this_month', 'next_month', 'last_90_days', 'next_90_days', 'last_n_days', 'next_n_days', 'n_days_ago', 'next_n_weeks', 'last_n_weeks', 'n_weeks_ago', 'next_n_months', 'last_n_months', 'n_months_ago', 'this_quarter', 'last_quarter', 'next_quarter', 'next_n_quarters', 'last_n_quarters', 'n_quarters_ago', 'this_year', 'last_year', 'next_year', 'next_n_years', 'last_n_years', 'n_years_ago', 'this_fiscal_quarter', 'last_fiscal_quarter', 'next_fiscal_quarter', 'next_n_fiscal_quarters', 'last_n_fiscal_quarters', 'n_fiscal_quarters_ago', 'this_fiscal_year', 'last_fiscal_year', 'next_fiscal_year', 'next_n_fiscal_years', 'last_n_fiscal_years', 'n_fiscal_years_ago', IntegralCurrencyLiteral, 'find', 'email', 'name', 'phone', 'sidebar', 'fields', 'metadata', 'pricebookid', 'network', 'snippet', 'target_length', 'division', 'returning', 'listview', ',', '.', Identifier}
Syntax error at 200:79: mismatched input ',' expecting {'instanceof', '[', ';', '.', '=', '>', '<', '?.', '?', '==', '===', '!=', '<>', '!==', '&&', '||', '??', '++', '--', '+', '-', '', '/', '&', '|', '^', '+=', '-=', '=', '/=', '&=', '|=', '^=', '<<=', '>>=', '>>>='}
Syntax error at 201:48: missing ';' at '('
Syntax error at 201:71: mismatched input ',' expecting {'instanceof', '[', ';', '.', '=', '>', '<', '?.', '?', '==', '===', '!=', '<>', '!==', '&&', '||', '??', '++', '--', '+', '-', '*'Syntax error at 204:40: missing ';' at 'WHERE'
Syntax error at 204:68: missing ';' at 'IN'
Syntax error at 204:86: missing ';' at 'SECURITY_ENFORCED'
Syntax error at 205:46: missing ';' at 'BY'
Syntax error at 205:55: missing ';' at '('
Syntax error at 206:8: extraneous input 'return' expecting {'abstract', 'after', 'before', 'class', 'enum', 'final', 'get', 'global', 'inherited', 'instanceof', 'interface', 'override', 'private', 'protected', 'public', 'set', 'sharing', 'static', 'switch', 'testmethod', 'transient', 'trigger', 'virtual', 'void', 'webservice', 'when', 'with', 'without', 'list', 'map', 'system', 'user', 'select', 'count', 'from', 'as', 'using', 'scope', 'where', 'order', 'by', 'limit', 'and', 'or', 'not', 'avg', 'count_distinct', 'min', 'max', 'sum', 'typeof', 'end', 'then', 'like', 'in', 'includes', 'excludes', 'asc', 'desc', 'nulls', 'first', 'last', 'group', 'all', 'rows', 'view', 'having', 'rollup', 'tolabel', 'offset', 'data', 'category', 'at', 'above', 'below', 'above_or_below', 'security_enforced', 'system_mode', 'user_mode', 'reference', 'cube', 'format', 'tracking', 'viewstat', 'custom', 'standard', 'distance', 'geolocation', 'calendar_month', 'calendar_quarter', 'calendar_year', 'day_in_month', 'day_in_week', 'day_in_year', 'day_only', 'fiscal_month', 'fiscal_quarter', 'fiscal_year', 'hour_in_day', 'week_in_month', 'week_in_year', 'converttimezone', 'yesterday', 'today', 'tomorrow', 'last_week', 'this_week', 'next_week', 'last_month', 'this_month', 'next_month', 'last_90_days', 'next_90_days', 'last_n_days', 'next_n_days', 'n_days_ago', 'next_n_weeks', 'last_n_weeks', 'n_weeks_ago', 'next_n_months', 'last_n_months', 'n_months_ago', 'this_quarter', 'last_quarter', 'next_quarter', 'next_n_quarters', 'last_n_quarters', 'n_quarters_ago', 'this_year', 'last_year', 'next_year', 'next_n_years', 'last_n_years', 'n_years_ago', 'this_fiscal_quarter', 'last_fiscal_quarter', 'next_fiscal_quarter', 'next_n_fiscal_quarters', 'last_n_fiscal_quarters', 'n_fiscal_quarters_ago', 'this_fiscal_year', 'last_fiscal_year', 'next_fiscal_year', 'next_n_fiscal_years', 'last_n_fiscal_years', 'n_fiscal_years_ago', IntegralCurrencyLiteral, 'find', 'email', 'name', 'phone', 'sidebar', 'fields', 'metadata', 'pricebookid', 'network', 'snippet', 'target_length', 'division', 'returning', 'listview', '{', '}', ';', '@', Identifier}
Syntax error at 209:4: mismatched input 'private' expecting

Steps To Reproduce

Update to @salesforce/sfdx-scanner 4.3.2

Expected Behavior

A proper scan of the class

Operating System

Ubuntu, windows

Salesforce CLI Version

@salesforce/cli/2.55.6 win32-x64 node-v18.12.0

Code Analyzer Plugin (@salesforce/sfdx-scanner) Version

@salesforce/sfdx-scanner 4.3.2

Additional Context (Screenshots, Files, etc)

No response

Workaround

No response

Urgency

High

@ashishrajbanshi ashishrajbanshi changed the title [BUG] <The Salesforce scanner throws a syntax error in an Apex class when using the GROUPING function in a SOQL query.> [BUG] The Salesforce scanner throws a syntax error in an Apex class when using the GROUPING function in a SOQL query Aug 21, 2024
@johnbelosf
Copy link
Collaborator

Thank you @ashishrajbanshi - I can't reproduce the exact error, but I can see that if I include your code snippet in one of my files, they are ignored when parsing.

This seems to be a gap in PMD. They switched parsing engines between the one we used in Code Analyzer 3 (PMD 6) and Code Analyzer 4 (PMD 7).

We'll investigate and raise it accordingly.

@ashishrajbanshi
Copy link
Author

@johnbelosf , can you please update the status of the issue ?

@stephen-carter-at-sf
Copy link
Collaborator

Created PMD issue: pmd/pmd#5182

Will keep this open until PMD has fixed the issue and we have incorporated their updates into Salesforce Code Analyzer

@stephen-carter-at-sf stephen-carter-at-sf added the WaitingForFixFromPMD Waiting for PMD to fix an issue so that we can incorporate the fix into Salesforce Code Analyzer label Aug 29, 2024
@kratoon
Copy link

kratoon commented Sep 23, 2024

We are affected as well when we switch to Code Analyzer 4. In our case it is caused by convertCurrency(amount) in SOQL. We can't upgrade to sfdx-scanner v4 before this is fixed :(

@jfeingold35
Copy link
Collaborator

@kratoon , PMD seems to have closed the Issue we created with them, and it looks like it's scheduled for their PMD 7.6.0 release. So based on current schedules, this will be fixed in our October release.
We appreciate your patience in the meantime.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
WaitingForFixFromPMD Waiting for PMD to fix an issue so that we can incorporate the fix into Salesforce Code Analyzer
Projects
None yet
Development

No branches or pull requests

5 participants