From 51fe50823ced6c01d4fe1d4e9bf37b6a42775052 Mon Sep 17 00:00:00 2001 From: Ben Lee Date: Thu, 18 Feb 2021 13:23:53 -0800 Subject: [PATCH] Fix jdeps collectTypeArguments stackoverflow error Fixes #485 --- .../io/bazel/kotlin/plugin/jdeps/JdepsGenExtension.kt | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/io/bazel/kotlin/plugin/jdeps/JdepsGenExtension.kt b/src/main/kotlin/io/bazel/kotlin/plugin/jdeps/JdepsGenExtension.kt index a7dabe8a0..8a2ecea18 100644 --- a/src/main/kotlin/io/bazel/kotlin/plugin/jdeps/JdepsGenExtension.kt +++ b/src/main/kotlin/io/bazel/kotlin/plugin/jdeps/JdepsGenExtension.kt @@ -19,7 +19,6 @@ import org.jetbrains.kotlin.descriptors.PropertyDescriptor import org.jetbrains.kotlin.descriptors.SourceElement import org.jetbrains.kotlin.descriptors.impl.LocalVariableDescriptor import org.jetbrains.kotlin.extensions.StorageComponentContainerContributor -import org.jetbrains.kotlin.load.java.descriptors.JavaClassDescriptor import org.jetbrains.kotlin.load.java.descriptors.JavaMethodDescriptor import org.jetbrains.kotlin.load.java.descriptors.JavaPropertyDescriptor import org.jetbrains.kotlin.load.java.sources.JavaSourceElement @@ -230,11 +229,14 @@ class JdepsGenExtension( collectTypeArguments(kotlinType) } - fun collectTypeArguments(kotlinType: KotlinType) { + fun collectTypeArguments(kotlinType: KotlinType, visitedKotlinTypes: MutableSet = mutableSetOf()) { + visitedKotlinTypes.add(kotlinType) kotlinType.arguments.map { it.type }.forEach { typeArgument -> addExplicitDep(typeArgument) typeArgument.supertypes().forEach { addImplicitDep(it) } - collectTypeArguments(typeArgument) + if (!visitedKotlinTypes.contains(typeArgument)) { + collectTypeArguments(typeArgument, visitedKotlinTypes) + } } } }