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

StackOverflowError in IDEA #261

Closed
klauss42 opened this issue Nov 27, 2023 · 4 comments · Fixed by #271
Closed

StackOverflowError in IDEA #261

klauss42 opened this issue Nov 27, 2023 · 4 comments · Fixed by #271

Comments

@klauss42
Copy link

Basic information

  • JDK version: 17
  • Kotlin 1.9.21
  • IDEA 2023.2.5

Steps to reproduce

If Axon plugin is enabled in IDEA, the following exception shows up regularly as IDE internal error:

java.lang.StackOverflowError
	at com.intellij.psi.SingleRootFileViewProvider.getPsiInner(SingleRootFileViewProvider.java:96)
	at com.intellij.psi.AbstractFileViewProvider.getPsi(AbstractFileViewProvider.java:185)
	at com.intellij.psi.impl.file.impl.FileManagerImpl.findFile(FileManagerImpl.java:359)
	at com.intellij.psi.impl.PsiManagerImpl.findFile(PsiManagerImpl.java:156)
	at com.intellij.javascript.testFramework.JsTestFileIndexingHandler.lambda$isTestFile$0(JsTestFileIndexingHandler.java:105)
	at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:923)
	at com.intellij.openapi.application.ReadAction.compute(ReadAction.java:76)
	at com.intellij.javascript.testFramework.JsTestFileIndexingHandler.isTestFile(JsTestFileIndexingHandler.java:105)
	at com.intellij.javascript.testing.JsTestSourcesFilter.isTestSource(JsTestSourcesFilter.java:12)
	at com.intellij.openapi.roots.TestSourcesFilter.isTestSources(TestSourcesFilter.java:31)
	at com.intellij.psi.search.GlobalSearchScopesCore$ProductionScopeFilter.contains(GlobalSearchScopesCore.java:143)
	at com.intellij.psi.search.DelegatingGlobalSearchScope.contains(DelegatingGlobalSearchScope.java:46)
	at com.intellij.psi.search.GlobalSearchScope$FileTypeRestrictionScope.contains(GlobalSearchScope.java:713)
	at com.intellij.psi.search.DelegatingGlobalSearchScope.contains(DelegatingGlobalSearchScope.java:46)
	at org.jetbrains.kotlin.idea.base.projectStructure.scope.KotlinSourceFilterScope.contains(KotlinSourceFilterScope.kt:46)
	at com.intellij.util.indexing.FileBasedIndexEx.filesInScopeWithBranches(FileBasedIndexEx.java:750)
	at com.intellij.psi.stubs.StubIndexEx.processElements(StubIndexEx.java:196)
	at com.intellij.psi.stubs.StubIndex.getElements(StubIndex.java:102)
	at com.intellij.psi.stubs.StubIndex.getElements(StubIndex.java:90)
	at org.jetbrains.kotlin.idea.stubindex.KotlinStringStubIndexHelper.get(KotlinStringStubIndexHelper.kt:28)
	at org.jetbrains.kotlin.idea.caches.resolve.IDEKotlinAsJavaSupport$findClassOrObjectDeclarations$1.invoke(IDEKotlinAsJavaSupport.kt:52)
	at org.jetbrains.kotlin.idea.caches.resolve.IDEKotlinAsJavaSupport$findClassOrObjectDeclarations$1.invoke(IDEKotlinAsJavaSupport.kt:51)
	at org.jetbrains.kotlin.idea.base.util.DumbModeUtils.runReadActionInSmartMode(DumbModeUtils.kt:18)
	at org.jetbrains.kotlin.idea.caches.resolve.IDEKotlinAsJavaSupport.findClassOrObjectDeclarations(IDEKotlinAsJavaSupport.kt:51)
	at org.jetbrains.kotlin.asJava.finder.JavaElementFinder.findClassesAndObjects(JavaElementFinder.kt:61)
	at org.jetbrains.kotlin.asJava.finder.JavaElementFinder.findClasses(JavaElementFinder.kt:46)
	at org.jetbrains.kotlin.asJava.finder.JavaElementFinder.findClass(JavaElementFinder.kt:35)
	at com.intellij.psi.impl.JavaPsiFacadeImpl.doFindClass(JavaPsiFacadeImpl.java:94)
	at com.intellij.psi.impl.JavaPsiFacadeImpl.findClass(JavaPsiFacadeImpl.java:72)
	at org.axonframework.intellij.ide.plugin.resolving.AggregateStructureResolver.inspect(AggregateStructureResolver.kt:113)
	at org.axonframework.intellij.ide.plugin.resolving.AggregateStructureResolver.inspect(AggregateStructureResolver.kt:115)
	at org.axonframework.intellij.ide.plugin.resolving.AggregateStructureResolver.inspect(AggregateStructureResolver.kt:115)
	at org.axonframework.intellij.ide.plugin.resolving.AggregateStructureResolver.inspect(AggregateStructureResolver.kt:115)

<snip>

The error disappears if disabling the Axon plugin.

Expected behaviour

Axon plugin should work as expected.

Actual behaviour

Plugin cannot be used in our projects anymore. It worked fine for months before.

@CodeDrivenMitch
Copy link
Member

@klauss42 Can you share with me your aggregate structure? It's seems there is a recursivity somewhere in the model, and we get an infinite loop in our analysis. Of course I can make an iteration guard, but I'd like to see if there's a possibility I missed in the structure resolver.

@klauss42
Copy link
Author

Hi Mitchell,
we have a lot aggregates in our project, but as you mentioned recursion, here is a simplified extract from an aggregate, that has been introduced recently. Maybe this kind of structure breaks the plugin?

The OrganizationalUnitAggregate holds a tree of organizational units to represent an arbitrary organization structure.

data class OrganizationalUnitId(val id: String = UUID.randomUUID().toString())

// Represents the root-OU of an OU-hierarchy-tree
@Aggregate
internal class OrganizationalUnitAggregate : OrganizationalUnitNode<OrganizationalUnitEntity> {

  @AggregateIdentifier
  override lateinit var organizationalUnitId: OrganizationalUnitId

  @AggregateMember
  override val children = mutableListOf<OrganizationalUnitEntity>()

}

// Represents a non-root OU in the OU-hierarchy-tree
internal class OrganizationalUnitEntity(
  @EntityId
  override var organizationalUnitId: OrganizationalUnitId,
) : OrganizationalUnitNode<OrganizationalUnitEntity> {

  @AggregateMember
  override val children: MutableList<OrganizationalUnitEntity> = mutableListOf()
}

// Represents any node of an OU-hierarchy-tree, either the root (Aggregate) or any
// other non-root-node (Entity); T = Type of children
internal interface OrganizationalUnitNode<T> where T : OrganizationalUnitNode<T> {

  var organizationalUnitId: OrganizationalUnitId
  val children: MutableList<T>

  fun addChild(child: T) {
    children.add(child)
  }

  fun removeChild(childOrganizationalUnitId: OrganizationalUnitId) {
    children.removeIf { node -> node.organizationalUnitId == childOrganizationalUnitId }
  }
}

Klaus

@CodeDrivenMitch
Copy link
Member

Yep that will be the recursion! I made a PR that will resolve this. I will release 0.8.5 as soon as that's merged.

@klauss42
Copy link
Author

Just to confirm: New version 0.8.5 now works in IDEA

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants