Skip to content

[apex] Parser error when using CALENDAR_YEAR() in SOQL #6478

@andruts

Description

@andruts

Affects PMD Version:
Pipeline: 7.10.0
Visual Studio Code Extension: 7.15.0
PMD CLI: 7.22.0

Description:

SOQL with GROUP BY ROLLUP and CALENDAR_YEAR.

Exception Stacktrace:

Syntax error at 279:21: mismatched input '(' expecting {')', ','}
Syntax error at 279:41: mismatched input ',' expecting {'instanceof', ')', '[', '.', '=', '>', '<', '?.', '?', '==', '===', '!=', '<>', '!==', '&&', '||', '??', '++', '--', '+', '-', '*', '/', '&', '|', '^', '+=', '-=', '*=', '/=', '&=', '|=', '^=', '<<=', '>>=', '>>>='}
Syntax error at 284:8: missing ';' at 'ExternalId__c'
Syntax error at 284:45: missing ';' at 'NULLS'
Syntax error at 285:34: missing ';' at 'ASC'
Syntax error at 285:44: missing ';' at 'FIRST'
Syntax error at 286:21: missing ';' at '('
Syntax error at 286:46: missing ';' at 'NULLS'
Syntax error at 287:6: missing ';' at 'LIMIT'
Syntax error at 288:4: mismatched input ']' expecting {'instanceof', '[', ';', '.', '=', '>', '<', '?.', '?', '==', '===', '!=', '<>', '!==', '&&', '||', '??', '++', '--', '+', '-', '*', '/', '&', '|', '^', '+=', '-=', '*=', '/=', '&=', '|=', '^=', '<<=', '>>=', '>>>='}
[INFO] An error occurred while executing PMD.

Code Sample demonstrating the issue:

SELECT
        ExternalId__c,
        CALENDAR_YEAR(CustomDateField__c) year,
        SUM(CustomAmountField__c) amount,
        COUNT(Id) counter
      FROM
        CustomObject__c
      GROUP BY ROLLUP(
        CALENDAR_YEAR(CustomDateField__c),
        ExternalId__c
      )
      ORDER BY
        ExternalId__c ASC NULLS FIRST,
        CALENDAR_YEAR(CustomDateField__c) ASC NULLS LAST
      LIMIT 2000

Steps to reproduce:

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

  1. Run Apex Static Analysis: On File

Running PMD through: [CLI | Ant | Maven | Gradle | Designer | Other]
CLI
Visual Studio Code

Metadata

Metadata

Assignees

No one assigned

    Labels

    a:bugPMD crashes or fails to analyse a file.in:grammarAbout the grammar of a lexer or parser, eg, a parse/lex exception

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions