Skip to content

Collection.toArray(T[] a) test generation fails at soot.Scene.getSootClass #387

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

Closed
alisevych opened this issue Jul 4, 2022 · 1 comment · Fixed by #400
Closed

Collection.toArray(T[] a) test generation fails at soot.Scene.getSootClass #387

alisevych opened this issue Jul 4, 2022 · 1 comment · Fixed by #400
Assignees
Labels
ctg-bug Issue is a bug

Comments

@alisevych
Copy link
Member

alisevych commented Jul 4, 2022

Description

Java 11 feature
Test generation for method Collection.toArray(T[] a) fails with RuntimeException: at soot.Scene.getSootClass

To Reproduce

Steps to reproduce the behavior:

  1. Define JDK-11 as primary (Path, JAVA_HOME)
  2. Open IntelliJ IDEA
  3. Plugin is installed
  4. A Maven project is opened with SDK 11 used
  5. Add a class using Collection.toArray(T[] a) - with NON-empty array, like that:
import java.util.List;

public class CollectionToArrayExample {

    public void method() {
        List<String> list = List.of("uno", "trez", "quatro");

        Object[] strings1 = list.toArray();

        String[] strings2a = list.toArray(new String[list.size()]);
        String[] strings2b = list.toArray(new String[0]);

        for (Object  str : strings2a) {
            System.out.println(str);
        }
    }
}

Expected behavior

Tests are supposed to be generated.

Actual behavior

The following exception is thrown and displayed as error in IDE:

java.lang.RuntimeException: 
Aborting: can't find classfile java.lang.Object
	at soot.Scene.getSootClass(Scene.java:1176)
	at org.utbot.engine.TypeResolverKt.getOBJECT_TYPE(TypeResolver.kt:316)
	at org.utbot.engine.ExtensionsKt.isJavaLangObject(Extensions.kt:134)
	at org.utbot.engine.pc.Z3TranslatorVisitor.filterInappropriateTypes(Z3TranslatorVisitor.kt:210)
	at org.utbot.engine.pc.Z3TranslatorVisitor.visit(Z3TranslatorVisitor.kt:165)
	at org.utbot.engine.pc.Z3TranslatorVisitor.visit(Z3TranslatorVisitor.kt:35)
	at org.utbot.engine.pc.UtIsExpression.accept(UtExpression.kt:349)
	at org.utbot.engine.pc.Z3TranslatorVisitor.translate(Z3TranslatorVisitor.kt:49)
	at org.utbot.engine.pc.UtSolver.check(UtSolver.kt:228)
	at org.utbot.engine.selectors.BasePathSelector.checkUnsat(BasePathSelector.kt:64)
	at org.utbot.engine.selectors.BasePathSelector.checkUnsatIfFork(BasePathSelector.kt:70)
	at org.utbot.engine.selectors.BasePathSelector.poll(BasePathSelector.kt:83)
	at org.utbot.engine.UtBotSymbolicEngine$traverseImpl$1.invokeSuspend(UtBotSymbolicEngine.kt:509)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
	at kotlinx.coroutines.EventLoopImplBase.processNextEvent(EventLoop.common.kt:274)
	at kotlinx.coroutines.BlockingCoroutine.joinBlocking(Builders.kt:84)
	at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking(Builders.kt:59)
	at kotlinx.coroutines.BuildersKt.runBlocking(Unknown Source)
	at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking$default(Builders.kt:38)
	at kotlinx.coroutines.BuildersKt.runBlocking$default(Unknown Source)
	at org.utbot.common.ConcurrencyKt.runBlockingWithCancellationPredicate(Concurrency.kt:38)
	at org.utbot.framework.plugin.api.UtBotTestCaseGenerator$generateForSeveralMethods$4.invoke(UtBotTestCaseGenerator.kt:279)
	at org.utbot.framework.plugin.api.UtBotTestCaseGenerator$generateForSeveralMethods$4.invoke(UtBotTestCaseGenerator.kt:56)
	at org.utbot.common.ConcurrencyKt.runIgnoringCancellationException(Concurrency.kt:47)
	at org.utbot.framework.plugin.api.UtBotTestCaseGenerator.generateForSeveralMethods(UtBotTestCaseGenerator.kt:278)
	at org.utbot.framework.plugin.api.UtBotTestCaseGenerator.generateForSeveralMethods$default(UtBotTestCaseGenerator.kt:265)
	at org.utbot.intellij.plugin.generator.CodeGenerator.generateForSeveralMethods(CodeGenerator.kt:55)
	at org.utbot.intellij.plugin.ui.UtTestsDialogProcessor$createTests$2$1.run(UtTestsDialogProcessor.kt:174)
	at com.intellij.openapi.progress.impl.CoreProgressManager.startTask(CoreProgressManager.java:442)
	at com.intellij.openapi.progress.impl.ProgressManagerImpl.startTask(ProgressManagerImpl.java:114)
	at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$runProcessWithProgressAsynchronously$5(CoreProgressManager.java:493)
	at com.intellij.openapi.progress.impl.ProgressRunner.lambda$submit$3(ProgressRunner.java:244)
	at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$runProcess$2(CoreProgressManager.java:189)
	at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$executeProcessUnderProgress$12(CoreProgressManager.java:608)
	at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:683)
	at com.intellij.openapi.progress.impl.CoreProgressManager.computeUnderProgress(CoreProgressManager.java:639)
	at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:607)
	at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:60)
	at com.intellij.openapi.progress.impl.CoreProgressManager.runProcess(CoreProgressManager.java:176)
	at com.intellij.openapi.progress.impl.ProgressRunner.lambda$submit$4(ProgressRunner.java:244)
	at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1700)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:668)
	at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:665)
	at java.base/java.security.AccessController.doPrivileged(Native Method)
	at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1.run(Executors.java:665)
	at java.base/java.lang.Thread.run(Thread.java:829)

Additional context

Only the first run of the test generation crashes.

@Damtev
Copy link
Member

Damtev commented Jul 4, 2022

Cannot reproduce the error but another bug is discovered - no executions are generated because List#of returns real List instead of UT wrapper UtArrayList. Fixed in #400

@alexeyfridman alexeyfridman moved this to Todo in UTBot Java Jul 6, 2022
@JaneEugenia JaneEugenia moved this from Todo to Done in UTBot Java Sep 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ctg-bug Issue is a bug
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants