Skip to content

Test generation for infix function may generate exception because UtUtils not found by other part of code #1256

Closed
@tyuldashev

Description

@tyuldashev

Description

Exception NoSuchElementException: Array is empty thrown during test generation for Kotlin class

To Reproduce

Steps to reproduce the behavior:

  1. In UTBot settings set Generated test language to Kotlin other leave default
  2. It seems that test root should be empty, so remove everything previously generated including packages
  3. Generate tests for following code
class Person(val name: String) {
    val likedPeople = mutableListOf<Person>()
    infix fun likes(other: Person): MutableList<Person> {
        likedPeople.add(other); return likedPeople; }
}

Expected behavior

Tests are generated without errors.

Actual behavior

Exception thrown at the end of test generation

Visual proofs (screenshots, logs, images)

...
java.util.NoSuchElementException: Array is empty.
	at kotlin.collections.ArraysKt___ArraysKt.first(_Arrays.kt:1012)
	at org.utbot.intellij.plugin.generator.CodeGenerationController$createOrUpdateUtilClass$$inlined$runReadAction$1.compute(actions.kt:60)
	at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:928)
	at org.utbot.intellij.plugin.generator.CodeGenerationController.createOrUpdateUtilClass(CodeGenerationController.kt:891)
	at org.utbot.intellij.plugin.generator.CodeGenerationController.createUtilityClassIfNeed(CodeGenerationController.kt:227)
	at org.utbot.intellij.plugin.generator.CodeGenerationController.access$createUtilityClassIfNeed(CodeGenerationController.kt:81)
	at org.utbot.intellij.plugin.generator.CodeGenerationController$generateTests$2$1$1$1.run(CodeGenerationController.kt:151)
	at org.utbot.intellij.plugin.util.IntelliJApiHelper$run$wrapper$1.run(IntelliJApiHelper.kt:26)
	at org.utbot.intellij.plugin.util.IntelliJApiHelper$run$$inlined$runWriteAction$1.compute(actions.kt:60)
	at com.intellij.openapi.application.impl.ApplicationImpl.lambda$runWriteAction$13(ApplicationImpl.java:1032)
	at com.intellij.openapi.application.impl.ApplicationImpl.runWriteActionWithClass(ApplicationImpl.java:1011)
	at com.intellij.openapi.application.impl.ApplicationImpl.runWriteAction(ApplicationImpl.java:1032)
	at org.utbot.intellij.plugin.util.IntelliJApiHelper.run(IntelliJApiHelper.kt:62)
	at org.utbot.intellij.plugin.generator.CodeGenerationController$generateTests$2$1$1.run(CodeGenerationController.kt:150)
	at org.utbot.intellij.plugin.util.IntelliJApiHelper$run$wrapper$1.run(IntelliJApiHelper.kt:26)
	at org.utbot.intellij.plugin.util.IntelliJApiHelper$run$$inlined$invokeLater$1.run(ApplicationUtils.kt:94)
	at com.intellij.openapi.application.TransactionGuardImpl.runWithWritingAllowed(TransactionGuardImpl.java:209)
	at com.intellij.openapi.application.TransactionGuardImpl.access$100(TransactionGuardImpl.java:21)
	at com.intellij.openapi.application.TransactionGuardImpl$1.run(TransactionGuardImpl.java:191)
	at com.intellij.openapi.application.impl.ApplicationImpl.runIntendedWriteActionOnCurrentThread(ApplicationImpl.java:881)
	at com.intellij.openapi.application.impl.ApplicationImpl$3.run(ApplicationImpl.java:513)
	at com.intellij.openapi.application.impl.FlushQueue.doRun(FlushQueue.java:75)
	at com.intellij.openapi.application.impl.FlushQueue.runNextEvent(FlushQueue.java:118)
	at com.intellij.openapi.application.impl.FlushQueue.flushNow(FlushQueue.java:42)
	at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:318)
	at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:779)
	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:730)
	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:724)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
	at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:749)
	at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.java:918)
	at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:766)
	at com.intellij.ide.IdeEventQueue.lambda$dispatchEvent$6(IdeEventQueue.java:450)
	at com.intellij.openapi.progress.impl.CoreProgressManager.computePrioritized(CoreProgressManager.java:791)
	at com.intellij.ide.IdeEventQueue.lambda$dispatchEvent$7(IdeEventQueue.java:449)
	at com.intellij.openapi.application.TransactionGuardImpl.performActivity(TransactionGuardImpl.java:105)
	at com.intellij.ide.IdeEventQueue.performActivity(IdeEventQueue.java:624)
	at com.intellij.ide.IdeEventQueue.lambda$dispatchEvent$8(IdeEventQueue.java:447)
	at com.intellij.openapi.application.impl.ApplicationImpl.runIntendedWriteActionOnCurrentThread(ApplicationImpl.java:881)
	at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:493)
	at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:207)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:117)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105)
	at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:92)

Additional context

That seems happen only once after IDEA start, so if it's not reproducible immediately please try to remove everything under test source root and restart IDEA.

Problem with deepEquals() described in #1255

Metadata

Metadata

Assignees

Labels

ctg-bugIssue is a buglang-kotlinIssue is related to Kotlin language support

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions