Skip to content

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

Closed

Description

@alisevych

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

Activity

  1. assigned and unassigned on Aug 26, 2022
  2. assigned
    and
    dtim
    and unassigned on Sep 7, 2022
  3. added this to the Release preparation milestone on Sep 7, 2022
  4. moved this from Todo to In Progress in UTBot Javaon Sep 19, 2022
  5. added
    spec-release-tailingsFailed to include in the current release, let's include it in the next one
    on Sep 28, 2022
  6. removed this from the Release preparation milestone on Sep 28, 2022
  7. Damtev commented on Oct 5, 2022

    @Damtev
    Member
    • 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.
  8. Markoutte commented on Oct 5, 2022

    @Markoutte
    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) } }
    
  9. added this to the 2022.12 Release milestone on Oct 7, 2022
  10. Repository owner moved this from In Progress to Done in UTBot Javaon Oct 18, 2022
  11. self-assigned this
    on Oct 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

ctg-bugIssue is a bugspec-release-tailingsFailed to include in the current release, let's include it in the next one

Type

No type

Projects

Relationships

None yet

Development

No branches or pull requests

Issue actions