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] TYPEOF in sub-query throws error #4922

Open
YodaDaCoda opened this issue Apr 4, 2024 · 0 comments · May be fixed by #4977
Open

[apex] TYPEOF in sub-query throws error #4922

YodaDaCoda opened this issue Apr 4, 2024 · 0 comments · May be fixed by #4977
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

Comments

@YodaDaCoda
Copy link
Contributor

YodaDaCoda commented Apr 4, 2024

Affects PMD Version:

v7.0.0

Description:

When a sub-query uses TYPEOF keyword to query related fields from a polymorphic field object, PMD throws a ParseException.

Exception Stacktrace:

> pmd check --dir .\force-app\main\default\classes\TypeofTest.cls --rulesets=.ci/pmd-apex.xml
.\force-app\main\default\classes\TypeofTest.cls	-	ParseException: Parse exception: com.google.summit.SummitAST$ParseException: Failed to parse .\force-app\main\default\classes\TypeofTest.cls: Syntax error at 18:7: missing 'from' at 'WHEN'
Syntax error at 18:18: missing ')' at 'THEN'
Syntax error at 18:23: missing 'from' at 'Name'
Syntax error at 19:12: mismatched input 'User' expecting {'for', 'update', 'with', 'using', 'where', 'order', 'limit', 'group', 'all', 'offset', ']', ','}
Syntax error at 19:22: missing ';' at 'Name'
Syntax error at 21:5: missing ';' at 'FROM'
Syntax error at 22:4: mismatched input ')' expecting {'for', 'update', 'with', 'using', 'where', 'order', 'limit', 'group', 'all', 'offset', ']', ','}
Syntax error at 24:2: extraneous input ']' expecting ';'

Code Sample demonstrating the issue:

public class TypeofTest {
	static void test() {
		Case c = [
			SELECT
				Id,
				Subject,
				Description,
				TYPEOF Owner
					WHEN Group THEN Name
					WHEN User THEN Name
				END,
				(
					SELECT
						Id,
						Subject,
						Description,
						TYPEOF Owner
							WHEN Group THEN Name
							WHEN User THEN Name
						END
					FROM Cases
				)
			FROM Case
		];
	}
}

Steps to reproduce:

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

  1. Run PMD against the provided sample class

Running PMD through:
CLI

Additional information:

This appears to be an issue with the apex-parser library v3.6.0 not properly supporting the TYPEOF in sub-queries. The unreleased v4.0.0 does, but summit-ast will need to be updated for the TriggerBlock changes.

@YodaDaCoda YodaDaCoda added the a:bug PMD crashes or fails to analyse a file. label Apr 4, 2024
@adangel adangel added the in:grammar About the grammar of a lexer or parser, eg, a parse/lex exception label Apr 4, 2024
aaronhurst-google pushed a commit to google/summit-ast that referenced this issue Apr 16, 2024
This upgrades apex-parser to the new version and adjust to the grammar changes (trigger block)

https://github.com/apex-dev-tools/apex-parser/releases/tag/v4.0.0

This upgrade also contains a fix for typeof needed in pmd/pmd#4922 .
adangel added a commit to adangel/pmd that referenced this issue Apr 26, 2024
@adangel adangel linked a pull request Apr 26, 2024 that will close this issue
4 tasks
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