diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md
index 9cee48758e..95b6ef916b 100644
--- a/docs/pages/release_notes.md
+++ b/docs/pages/release_notes.md
@@ -20,6 +20,7 @@ This is a {{ site.pmd.release_type }} release.
(ApexCRUDViolation, CognitiveComplexity, OperationWithLimitsInLoop)
* [#5163](https://github.com/pmd/pmd/issues/5163): \[apex] Parser error when using toLabel in SOSL query
* [#5182](https://github.com/pmd/pmd/issues/5182): \[apex] Parser error when using GROUPING in a SOQL query
+ * [#5218](https://github.com/pmd/pmd/issues/5218): \[apex] Parser error when using nested subqueries in SOQL
* core
* [#5059](https://github.com/pmd/pmd/issues/5059): \[core] xml output doesn't escape CDATA inside its own CDATA
* [#5201](https://github.com/pmd/pmd/issues/5201): \[core] PMD sarif schema file points to nonexistent location
diff --git a/pmd-apex/src/test/java/net/sourceforge/pmd/lang/apex/ast/ApexTreeDumpTest.java b/pmd-apex/src/test/java/net/sourceforge/pmd/lang/apex/ast/ApexTreeDumpTest.java
index 54294e6012..4f918f72e0 100644
--- a/pmd-apex/src/test/java/net/sourceforge/pmd/lang/apex/ast/ApexTreeDumpTest.java
+++ b/pmd-apex/src/test/java/net/sourceforge/pmd/lang/apex/ast/ApexTreeDumpTest.java
@@ -94,4 +94,12 @@ class ApexTreeDumpTest extends BaseTreeDumpTest {
void triggersWithMethods() {
doTest("TriggerWithMethod");
}
+
+ /**
+ * @see [apex] Parser error when using nested subqueries in SOQL
+ */
+ @Test
+ void nestedSubqueries() {
+ doTest("NestedSubqueries");
+ }
}
diff --git a/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/ast/NestedSubqueries.cls b/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/ast/NestedSubqueries.cls
new file mode 100644
index 0000000000..e9b4dbec9a
--- /dev/null
+++ b/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/ast/NestedSubqueries.cls
@@ -0,0 +1,5 @@
+public with sharing class NestedSubqueries {
+ public NestedSubqueries() {
+ Schema.Account account = [SELECT Id, (SELECT Id, (SELECT Id FROM CaseComments) FROM Cases) FROM Account LIMIT 1];
+ }
+}
diff --git a/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/ast/NestedSubqueries.txt b/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/ast/NestedSubqueries.txt
new file mode 100644
index 0000000000..9e6c923b9d
--- /dev/null
+++ b/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/ast/NestedSubqueries.txt
@@ -0,0 +1,12 @@
++- ApexFile[@DefiningType = "NestedSubqueries", @RealLoc = true]
+ +- UserClass[@DefiningType = "NestedSubqueries", @Image = "NestedSubqueries", @InterfaceNames = (), @Nested = false, @RealLoc = true, @SimpleName = "NestedSubqueries", @SuperClassName = ""]
+ +- ModifierNode[@Abstract = false, @DefiningType = "NestedSubqueries", @DeprecatedTestMethod = false, @Final = false, @Global = false, @InheritedSharing = false, @Modifiers = 1, @Override = false, @Private = false, @Protected = false, @Public = true, @RealLoc = true, @Static = false, @Test = false, @TestOrTestSetup = false, @Transient = false, @Virtual = false, @WebService = false, @WithSharing = true, @WithoutSharing = false]
+ +- Method[@Arity = 0, @CanonicalName = "", @Constructor = true, @DefiningType = "NestedSubqueries", @Image = "NestedSubqueries", @RealLoc = true, @ReturnType = "void", @StaticInitializer = false]
+ +- ModifierNode[@Abstract = false, @DefiningType = "NestedSubqueries", @DeprecatedTestMethod = false, @Final = false, @Global = false, @InheritedSharing = false, @Modifiers = 1, @Override = false, @Private = false, @Protected = false, @Public = true, @RealLoc = true, @Static = false, @Test = false, @TestOrTestSetup = false, @Transient = false, @Virtual = false, @WebService = false, @WithSharing = false, @WithoutSharing = false]
+ +- BlockStatement[@CurlyBrace = true, @DefiningType = "NestedSubqueries", @RealLoc = true]
+ +- VariableDeclarationStatements[@DefiningType = "NestedSubqueries", @RealLoc = true]
+ +- ModifierNode[@Abstract = false, @DefiningType = "NestedSubqueries", @DeprecatedTestMethod = false, @Final = false, @Global = false, @InheritedSharing = false, @Modifiers = 0, @Override = false, @Private = false, @Protected = false, @Public = false, @RealLoc = false, @Static = false, @Test = false, @TestOrTestSetup = false, @Transient = false, @Virtual = false, @WebService = false, @WithSharing = false, @WithoutSharing = false]
+ +- VariableDeclaration[@DefiningType = "NestedSubqueries", @Image = "account", @RealLoc = true, @Type = "Schema.Account"]
+ +- SoqlExpression[@CanonicalQuery = "SELECT Id, (SELECT Id, (SELECT Id FROM CaseComments) FROM Cases) FROM Account LIMIT 1", @DefiningType = "NestedSubqueries", @Query = "SELECT Id, (SELECT Id, (SELECT Id FROM CaseComments) FROM Cases) FROM Account LIMIT 1", @RealLoc = true]
+ +- VariableExpression[@DefiningType = "NestedSubqueries", @Image = "account", @RealLoc = true]
+ +- EmptyReferenceExpression[@DefiningType = null, @RealLoc = false]