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

Functional interfaces defined as class members - InaccessibleObjectException on test generation #448

Closed
Tracked by #1187
alisevych opened this issue Jul 7, 2022 · 2 comments · Fixed by #1101
Closed
Tracked by #1187
Assignees
Labels
ctg-bug Issue is a bug spec-release-tailings Failed to include in the current release, let's include it in the next one

Comments

@alisevych
Copy link
Member

alisevych commented Jul 7, 2022

Description

Test generation for Functional interfaces defined as class members - fails with InaccessibleObjectException from constructCompositeModel

To Reproduce

Steps to reproduce the behavior:

  1. Open IntelliJ IDEA
  2. Plugin is installed
  3. Create a new project with JDK 8
  4. Add a class LambdaVarExample (see below)
  5. Run test generation
  6. Repeat 3-5 steps for a project with JDK 11
import java.util.function.Predicate;

public class LambdaVarExample {

    private Predicate<? super String> byCondition = l -> l.contains("b");

    public void runTest(String input) {
        if (byCondition.test(input)) {
            firstScenario();
        } else {
            secondScenario();
        }
    }

    private void firstScenario() {
        System.out.println("1");
    }

    private void secondScenario() {
        System.out.println("2");
    }

}

Expected behavior

5-6. Tests are supposed to be generated without errors.

Actual behavior

An error test is generated with information about...
5. JDK 8 - ClassNotFoundException in concrete...
6. JDK 11 - InaccessibleObjectException in constructCompositeModel.

Visual proofs (screenshots, logs, images)

  1. JDK 8 error:
public void testRunTest_errors() {
        // Couldn't generate some tests. List of errors:
        // 
        // 1 occurrences of:
        // Default concrete execution failed

        // 1 occurrences of:
        /* Error in the child process |> java.lang.ClassNotFoundException: jdk.internal.logger.SimpleConsoleLogger$CallerFinder
        		at java.net.URLClassLoader.findClass(URLClassLoader.java:387)
        		at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
        		at org.utbot.instrumentation.process.HandlerClassesLoader.loadClass(ChildProcess.kt:38)
        		at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
        		at org.utbot.framework.concrete.MockValueConstructor.kClass(MockValueConstructor.kt:470)
        		at org.utbot.framework.concrete.MockValueConstructor.javaClass(MockValueConstructor.kt:455)
        		at org.utbot.framework.concrete.MockValueConstructor.constructObject(MockValueConstructor.kt:158)
        		at org.utbot.framework.concrete.MockValueConstructor.construct(MockValueConstructor.kt:127)
        		at org.utbot.framework.concrete.MockValueConstructor.constructObject(MockValueConstructor.kt:184)
        		at org.utbot.framework.concrete.MockValueConstructor.construct(MockValueConstructor.kt:127)
        		at org.utbot.framework.concrete.MockValueConstructor.constructMethodParameters(MockValueConstructor.kt:104)
        		at org.utbot.framework.concrete.UtExecutionInstrumentation.invoke(UtExecutionInstrumentation.kt:144)
        		at org.utbot.framework.concrete.UtExecutionInstrumentation.invoke(UtExecutionInstrumentation.kt:107)
        		at org.utbot.instrumentation.process.ChildProcessKt.loop(ChildProcess.kt:133)
        		at org.utbot.instrumentation.process.ChildProcessKt.main(ChildProcess.kt:77)
        		at org.utbot.instrumentation.process.ChildProcessKt.main(ChildProcess.kt)
        	 */

    }
  1. JDK 11 error:
public void testRunTest_errors() {
        // Couldn't generate some tests. List of errors:
        // 
        // 1 occurrences of:
        /* Error in the child process |> java.lang.reflect.InaccessibleObjectException: Unable to make
        field private boolean jdk.internal.logger.SimpleConsoleLogger$CallerFinder.lookingForLogger accessible: module java.base does not "opens
        jdk.internal.logger" to unnamed module @29e6eb25
        		at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:340)
        		at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:280)
        		at java.base/java.lang.reflect.Field.checkCanSetAccessible(Field.java:176)
        		at java.base/java.lang.reflect.Field.setAccessible(Field.java:170)
        		at org.utbot.framework.concrete.UtModelConstructor.constructCompositeModel(UtModelConstructor.kt:356)
        		at org.utbot.framework.concrete.UtModelConstructor.constructFromAny(UtModelConstructor.kt:239)
        		at org.utbot.framework.concrete.UtModelConstructor.construct(UtModelConstructor.kt:107)
        		at org.utbot.framework.concrete.UtModelConstructor.constructCompositeModel(UtModelConstructor.kt:285)
        		at org.utbot.framework.concrete.UtModelConstructor.constructFromAny(UtModelConstructor.kt:239)
        		at org.utbot.framework.concrete.UtModelConstructor.construct(UtModelConstructor.kt:107)
        		at org.utbot.framework.concrete.UtExecutionInstrumentation$invoke$$inlined$withReflection$lambda$1.invoke(UtExecutionInstrumentation.kt:179)
        		at org.utbot.framework.concrete.UtExecutionInstrumentation$invoke$$inlined$withReflection$lambda$1.invoke(UtExecutionInstrumentation.kt:107)
        		at org.utbot.framework.concrete.UtExecutionInstrumentation.withStaticFields(UtExecutionInstrumentation.kt:269)
        		at org.utbot.framework.concrete.UtExecutionInstrumentation.invoke(UtExecutionInstrumentation.kt:153)
        		at org.utbot.framework.concrete.UtExecutionInstrumentation.invoke(UtExecutionInstrumentation.kt:107)
        		at org.utbot.instrumentation.process.ChildProcessKt.loop(ChildProcess.kt:133)
        		at org.utbot.instrumentation.process.ChildProcessKt.main(ChildProcess.kt:77)
        		at org.utbot.instrumentation.process.ChildProcessKt.main(ChildProcess.kt)
        	 */

    }

Environment

Windows 10 Pro
IntelliJ IDEA 2022.1.3
JDK 8, 11
One of the latest plugin build: https://github.com/UnitTestBot/UTBotJava/actions/runs/2621106151

@alisevych alisevych added the ctg-bug Issue is a bug label Jul 7, 2022
@dtim dtim assigned ArsenHD and unassigned dtim Aug 26, 2022
@alisevych alisevych assigned Damtev and dtim and unassigned ArsenHD Sep 7, 2022
@alisevych alisevych added this to the Release preparation milestone Sep 7, 2022
@JaneEugenia JaneEugenia moved this to Todo in UTBot Java Sep 9, 2022
@JaneEugenia JaneEugenia moved this from Todo to In Progress in UTBot Java Sep 19, 2022
@denis-fokin denis-fokin added the spec-release-tailings Failed to include in the current release, let's include it in the next one label Sep 28, 2022
@denis-fokin denis-fokin removed this from the Release preparation milestone Sep 28, 2022
@Damtev
Copy link
Member

Damtev commented Oct 5, 2022

  • JDK 8 - cannot reproduce ClassNotFoundException, but got Default concrete execution failed error, which comes from fuzzer - @Markoutte take a look, please. Also, found wrong assertions from symbolic assertions (see the attached screenshot) - going to investigate.
    image
  • JDK 11 - found the mentioned exception in runIde logs, and no expected non-exceptional executions - going to investigate. Also, Default concrete execution failed error again - @Markoutte take a look too, please.

@Markoutte
Copy link
Collaborator

@Damtev looks like the problem that we cannot find lambda class to construct concrete "this" object. In this case the field cannot be created because Predicate uses a lambda. If we use anonymous class it works ok for fuzzer:

    private Predicate<? super String> byCondition = new Predicate<String>() {
        @Override
        public boolean test(String s) {
            return s.contains("b");
        }
    };

You can find the field gathering in UtModelConstructor#constructCompositeModel:295:

.forEach { it.withAccessibility { fields[it.fieldId] = construct(it.get(value), it.type.id) } }

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 spec-release-tailings Failed to include in the current release, let's include it in the next one
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

7 participants