From 13ad53ab593bf9f31ee4b9223cdaf56b92f8ff1b Mon Sep 17 00:00:00 2001 From: psteiger Date: Wed, 14 Feb 2024 10:56:09 -0500 Subject: [PATCH] Fix StackOverflowError on types with self-references --- .../main/kotlin/com/uber/xprocessing/ext/XType.kt | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/compiler/ast/src/main/kotlin/com/uber/xprocessing/ext/XType.kt b/compiler/ast/src/main/kotlin/com/uber/xprocessing/ext/XType.kt index 261291b9..e303ead3 100644 --- a/compiler/ast/src/main/kotlin/com/uber/xprocessing/ext/XType.kt +++ b/compiler/ast/src/main/kotlin/com/uber/xprocessing/ext/XType.kt @@ -312,8 +312,16 @@ fun XType.isPrimitive(): Boolean { } private fun XType.hasCollectionType(): Boolean { - return this.typeElement?.name.orEmpty() in collectionTypes || - typeArguments.any { it.hasCollectionType() } + val visited = mutableSetOf() + val queue = mutableListOf(this@hasCollectionType) + while (queue.isNotEmpty()) { + val type = queue.removeFirst() + if (type in visited) continue + if (type.typeElement?.name in collectionTypes) return true + visited.add(type) + queue.addAll(type.typeArguments) + } + return false } private val collectionTypes =