Skip to content

Error in Fuzzing test generation for code producing Function<String, Integer> #1419

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 Nov 24, 2022 · 1 comment · Fixed by #1424
Closed

Error in Fuzzing test generation for code producing Function<String, Integer> #1419

alisevych opened this issue Nov 24, 2022 · 1 comment · Fixed by #1424
Assignees
Labels
ctg-bug Issue is a bug priority-top-focus Top priority chosen by dev team

Comments

@alisevych
Copy link
Member

Description

Array has more than one element error in Errors report for
Fuzzing test generation for code producing Function<String, Integer>

To Reproduce

  1. Run a project with JDK 11 in IntelliJ Idea
  2. Install one of the latest plugins from main
  3. Set Fuzzing only mode
  4. Add a Java class with the following function:
    Function<String, Integer> returnLambda(int buffer) {
        return s -> s.length() + buffer;
    }
  1. Generate tests for it

Expected behavior

Tests are supposed to be generated.

Actual behavior

An error test is generated with information about errors in the concrete executor:
Array has more than one element
No exceptions are present in concrete executor log , RD engine logs, idea.log
Only one about failed to save test report.

Visual proofs (screenshots, logs, images)

import java.util.function.Function;

public final class LambdaTest {
    ///region Test suites for executable org.utbot.examples.lambda.Lambda.returnLambda

    ///region Errors report for returnLambda

    public void testReturnLambda_errors() {
        // Couldn't generate some tests. List of errors:
        // 
        // 1 occurrences of:
        // Array has more than one element.

    }
    ///endregion

    ///endregion
}

Environment

Windows 10 Pro
IntelliJ IDEA 2022.2.3
Gradle , JDK 11

Additional context

IF Symbolic execution is turned on - a successful test is generated besides the error on.

@alisevych alisevych added the ctg-bug Issue is a bug label Nov 24, 2022
@korifey korifey moved this to Todo in UTBot Java Nov 24, 2022
@Markoutte
Copy link
Collaborator

Looks like the problem is caused by this change cc @SBOne-Kenobi . The stracktrace of the error is:

java.lang.IllegalArgumentException: Array has more than one element.
	at kotlin.collections.ArraysKt___ArraysKt.single(_Arrays.kt:2812)
	at org.utbot.framework.plugin.api.UtLambdaModel.getLambdaMethodId(Api.kt:578)
	at org.utbot.framework.codegen.tree.CgVariableConstructor.constructLambda(CgVariableConstructor.kt:127)
	at org.utbot.framework.codegen.tree.CgVariableConstructor.getOrCreateVariable(CgVariableConstructor.kt:113)
	at org.utbot.framework.codegen.tree.CgMethodConstructor.generateResultAssertions(CgMethodConstructor.kt:316)
	at org.utbot.framework.codegen.tree.CgMethodConstructor$createTestMethod$1$2$mainBody$1.invoke(CgMethodConstructor.kt:1390)
	at org.utbot.framework.codegen.tree.CgMethodConstructor$createTestMethod$1$2$mainBody$1.invoke(CgMethodConstructor.kt:1370)
	at org.utbot.framework.codegen.tree.CgMethodConstructor$createTestMethod$1$2.invoke(CgMethodConstructor.kt:1407)
	at org.utbot.framework.codegen.tree.CgMethodConstructor$createTestMethod$1$2.invoke(CgMethodConstructor.kt:1363)
	at org.utbot.framework.codegen.domain.context.CgContextOwner$block$1.invoke(CgContext.kt:231)
	at org.utbot.framework.codegen.domain.context.CgContextOwner$block$1.invoke(CgContext.kt:230)
	at org.utbot.framework.codegen.domain.context.CgContextOwner$DefaultImpls.withNameScope(CgContext.kt:323)
	at org.utbot.framework.codegen.domain.context.CgContext.withNameScope(CgContext.kt:432)
	at org.utbot.framework.codegen.domain.context.CgContextOwner$DefaultImpls.block(CgContext.kt:230)
	at org.utbot.framework.codegen.domain.context.CgContext.block(CgContext.kt:432)
	at org.utbot.framework.codegen.tree.CgMethodConstructor.block(CgMethodConstructor.kt)
	at org.utbot.framework.codegen.tree.CgMethodConstructor$testMethod$testMethod$1.invoke(CgMethodConstructor.kt:1846)
	at org.utbot.framework.codegen.tree.CgMethodConstructor$testMethod$testMethod$1.invoke(CgMethodConstructor.kt:1843)
	at org.utbot.framework.codegen.tree.BuildersKt.buildTestMethod(Builders.kt:108)
	at org.utbot.framework.codegen.tree.CgMethodConstructor.testMethod(CgMethodConstructor.kt:1843)
	at org.utbot.framework.codegen.tree.CgMethodConstructor.testMethod$default(CgMethodConstructor.kt:1802)
	at org.utbot.framework.codegen.tree.CgMethodConstructor$createTestMethod$1.invoke(CgMethodConstructor.kt:1363)
	at org.utbot.framework.codegen.tree.CgMethodConstructor$createTestMethod$1.invoke(CgMethodConstructor.kt:1356)
	at org.utbot.framework.codegen.tree.CgMethodConstructor.withTestMethodScope(CgMethodConstructor.kt:1717)
	at org.utbot.framework.codegen.tree.CgMethodConstructor.createTestMethod(CgMethodConstructor.kt:1356)
	at org.utbot.framework.codegen.tree.CgTestClassConstructor.createTest(CgTestClassConstructor.kt:188)
	at org.utbot.framework.codegen.tree.CgTestClassConstructor.constructTestSet(CgTestClassConstructor.kt:148)
	at org.utbot.framework.codegen.tree.CgTestClassConstructor$constructTestClass$1$3.invoke(CgTestClassConstructor.kt:98)
	at org.utbot.framework.codegen.tree.CgTestClassConstructor$constructTestClass$1$3.invoke(CgTestClassConstructor.kt:86)
	at org.utbot.framework.codegen.tree.BuildersKt.buildClassBody(Builders.kt:73)
	at org.utbot.framework.codegen.tree.CgTestClassConstructor$constructTestClass$1.invoke(CgTestClassConstructor.kt:86)
	at org.utbot.framework.codegen.tree.CgTestClassConstructor$constructTestClass$1.invoke(CgTestClassConstructor.kt:70)
	at org.utbot.framework.codegen.tree.BuildersKt.buildClass(Builders.kt:63)
	at org.utbot.framework.codegen.tree.CgTestClassConstructor.constructTestClass(CgTestClassConstructor.kt:70)
	at org.utbot.framework.codegen.tree.CgTestClassConstructor$construct$1$1.invoke(CgTestClassConstructor.kt:64)
	at org.utbot.framework.codegen.tree.CgTestClassConstructor$construct$1$1.invoke(CgTestClassConstructor.kt:64)
	at org.utbot.framework.codegen.domain.context.CgContext.withTestClassScope(CgContext.kt:535)
	at org.utbot.framework.codegen.tree.CgTestClassConstructor.withTestClassScope(CgTestClassConstructor.kt)
	at org.utbot.framework.codegen.tree.CgTestClassConstructor$construct$1.invoke(CgTestClassConstructor.kt:64)
	at org.utbot.framework.codegen.tree.CgTestClassConstructor$construct$1.invoke(CgTestClassConstructor.kt:63)
	at org.utbot.framework.codegen.tree.BuildersKt.buildClassFile(Builders.kt:48)
	at org.utbot.framework.codegen.tree.CgTestClassConstructor.construct(CgTestClassConstructor.kt:63)
	at org.utbot.framework.codegen.CodeGenerator$generateAsStringWithTestReport$1$1.invoke(CodeGenerator.kt:74)
	at org.utbot.framework.codegen.CodeGenerator$generateAsStringWithTestReport$1$1.invoke(CodeGenerator.kt:69)
	at org.utbot.framework.codegen.domain.context.CgContext.withTestClassFileScope(CgContext.kt:525)
	at org.utbot.framework.codegen.CodeGenerator$generateAsStringWithTestReport$1.invoke(CodeGenerator.kt:69)
	at org.utbot.framework.codegen.CodeGenerator$generateAsStringWithTestReport$1.invoke(CodeGenerator.kt:68)
	at org.utbot.framework.codegen.CodeGenerator.withCustomContext(CodeGenerator.kt:98)
	at org.utbot.framework.codegen.CodeGenerator.generateAsStringWithTestReport(CodeGenerator.kt:68)
	at org.utbot.framework.codegen.CodeGenerator.generateAsStringWithTestReport$default(CodeGenerator.kt:63)
	at org.utbot.framework.process.EngineMainKt$setup$4.invoke(EngineMain.kt:154)
	at org.utbot.framework.process.EngineMainKt$setup$4.invoke(EngineMain.kt:129)
	at org.utbot.rd.CallsSynchronizer$measureExecutionForTermination$1$1.invoke(ClientProcessUtil.kt:84)
	at org.utbot.rd.CallsSynchronizer.measureExecutionForTermination(ClientProcessUtil.kt:75)
	at org.utbot.rd.CallsSynchronizer$measureExecutionForTermination$1.invoke(ClientProcessUtil.kt:83)
	at com.jetbrains.rd.framework.IRdEndpoint$set$1.invoke(TaskInterfaces.kt:182)
	at com.jetbrains.rd.framework.IRdEndpoint$set$1.invoke(TaskInterfaces.kt:182)
	at com.jetbrains.rd.framework.impl.RdCall.onWireReceived(RdTask.kt:360)
	at com.jetbrains.rd.framework.MessageBroker$invoke$2$2.invoke(MessageBroker.kt:57)
	at com.jetbrains.rd.framework.MessageBroker$invoke$2$2.invoke(MessageBroker.kt:56)
	at com.jetbrains.rd.framework.impl.ProtocolContexts.readMessageContextAndInvoke(ProtocolContexts.kt:148)
	at com.jetbrains.rd.framework.MessageBroker$invoke$2.invoke(MessageBroker.kt:56)
	at com.jetbrains.rd.framework.MessageBroker$invoke$2.invoke(MessageBroker.kt:54)
	at com.jetbrains.rd.util.threading.SingleThreadSchedulerBase.queue$lambda-3(SingleThreadScheduler.kt:41)
	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.lang.Thread.run(Thread.java:829)

The problem is that functional interface has not only one abstract function but also can have default and static methods. For this case they are:

public abstract java.lang.Object java.util.function.Function.apply(java.lang.Object)
public static java.util.function.Function java.util.function.Function.identity()
public default java.util.function.Function java.util.function.Function.compose(java.util.function.Function)
public default java.util.function.Function java.util.function.Function.andThen(java.util.function.Function)
private static java.lang.Object java.util.function.Function.lambda$identity$2(java.lang.Object)
private java.lang.Object java.util.function.Function.lambda$andThen$1(java.util.function.Function,java.lang.Object)
private java.lang.Object java.util.function.Function.lambda$compose$0(java.util.function.Function,java.lang.Object)

Also, the issue is very hard to identify until CgTestClassConstructor#processFailure(testSet: CgMethodTestSet, failure: Throwable) just consumes an exception without any additional log printing. @sofurihafe Please, consider to add some error log printing.

@Markoutte Markoutte assigned SBOne-Kenobi and unassigned Markoutte Nov 25, 2022
Repository owner moved this from Todo to Done in UTBot Java Nov 25, 2022
@alisevych alisevych added this to the 2022.12 Release milestone Nov 30, 2022
@alisevych alisevych added the priority-top-focus Top priority chosen by dev team label Nov 30, 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 priority-top-focus Top priority chosen by dev team
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants