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

[apex] Parser error when using GROUPING in a SOQL query #5182

Closed
stephen-carter-at-sf opened this issue Aug 29, 2024 · 1 comment · Fixed by #5188
Closed

[apex] Parser error when using GROUPING in a SOQL query #5182

stephen-carter-at-sf opened this issue Aug 29, 2024 · 1 comment · Fixed by #5188
Labels
a:bug PMD crashes or fails to analyse a file. in:grammar About the grammar of a lexer or parser, eg, a parse/lex exception
Milestone

Comments

@stephen-carter-at-sf
Copy link

Affects PMD Version: 7.4.0

Make sure, to test with the latest PMD version.

Description:

This bug was surfaced through the salesforce code analyzer originally with forcedotcom/sfdx-scanner#1579

Exception Stacktrace:

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

Code Sample demonstrating the issue:

public class MyClassA3 {
    private List<AggregateResult> getDefects() {
        AggregateResult[] defects = [
            SELECT
              OBJ1__c O1,
              OBJ2__c O2,
              OBJ3__c O3,
              SUM(OBJ4__c) O4,
              GROUPING(OBJ1__c) O1Group,
              GROUPING(OBJ2__c) O2Group,
              GROUPING(OBJ3__c) O3Group
            FROM OBJ4__c
            GROUP BY ROLLUP(OBJ1__c, OBJ2__c, OBJ3__c)
        ];
        return defects;
    }
}

Steps to reproduce:

Please provide detailed steps for how we can reproduce the bug.

  1. Use PMD CLI to scan the class using any apex rules
@adangel adangel added the in:grammar About the grammar of a lexer or parser, eg, a parse/lex exception label Aug 29, 2024
@adangel adangel changed the title [apex] Syntax error in an Apex class when using the GROUPING function in a SOQL query [apex] Parser error when using GROUPING in a SOQL query Aug 30, 2024
@adangel adangel added this to the 7.6.0 milestone Sep 2, 2024
adangel added a commit to adangel/pmd that referenced this issue Sep 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:bug PMD crashes or fails to analyse a file. in:grammar About the grammar of a lexer or parser, eg, a parse/lex exception
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants