Skip to content

Concrete executor tries to create enum instances by reflection and fails #619

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
dtim opened this issue Jul 30, 2022 · 0 comments · Fixed by #907
Closed

Concrete executor tries to create enum instances by reflection and fails #619

dtim opened this issue Jul 30, 2022 · 0 comments · Fixed by #907
Assignees
Labels
ctg-bug Issue is a bug

Comments

@dtim
Copy link
Collaborator

dtim commented Jul 30, 2022

Description

In MockValueConstructor class, concrete executor creates objects using reflection. No special filtering is performed for enum classes. When the concrete executor tries to create instances of an enum, it fails with IllegalArgumentException, as it is specifically forbidden to create enums by reflection (the reason is to ensure that no difference instances of the same enum value can be created, so reference equality is always possible).

A special check for enums should be added, so that real values could be returned instead of new instances.

To Reproduce

Run the constest estimator with settings from the issue #300.

Expected behavior

No exceptions are thrown during the contest estimator run.

Actual behavior

An IllegalArgumentException is thrown when the concrete executor tries to create an instance of an enum class, and the corresponding org.utbot.instrumentation.util.ChildProcessError exception is thrown.

Visual proofs (screenshots, logs, images)

org.utbot.instrumentation.util.ChildProcessError: Error in the child process |> java.lang.IllegalArgumentException: Cannot reflectively create enum objects
	at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
	at org.utbot.framework.concrete.MockValueConstructor.call(MockValueConstructor.kt:455)
	at org.utbot.framework.concrete.MockValueConstructor.updateWithExecutableCallModel(MockValueConstructor.kt:381)
	at org.utbot.framework.concrete.MockValueConstructor.constructFromAssembleModel(MockValueConstructor.kt:360)
	at org.utbot.framework.concrete.MockValueConstructor.construct(MockValueConstructor.kt:129)
	at org.utbot.framework.concrete.MockValueConstructor.value(MockValueConstructor.kt:435)
	at org.utbot.framework.concrete.MockValueConstructor.updateWithExecutableCallModel(MockValueConstructor.kt:377)
	at org.utbot.framework.concrete.MockValueConstructor.constructFromAssembleModel(MockValueConstructor.kt:360)
	at org.utbot.framework.concrete.MockValueConstructor.construct(MockValueConstructor.kt:129)
	at org.utbot.framework.concrete.MockValueConstructor.constructMethodParameters(MockValueConstructor.kt:104)
	at org.utbot.framework.concrete.UtExecutionInstrumentation.invoke(UtExecutionInstrumentation.kt:143)
	at org.utbot.framework.concrete.UtExecutionInstrumentation.invoke(UtExecutionInstrumentation.kt:106)
	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)

	at org.utbot.instrumentation.ConcreteExecutor.executeAsync(ConcreteExecutor.kt:416) ~[main/:?]
	at org.utbot.instrumentation.ConcreteExecutor$executeAsync$1.invokeSuspend(ConcreteExecutor.kt) ~[main/:?]
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33) [kotlin-stdlib-1.4.30.jar:1.4.30-release-302 (1.4.30)]
	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106) [kotlinx-coroutines-core-jvm-1.4.1.jar:?]
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_342]
	at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_342]
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180) [?:1.8.0_342]
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) [?:1.8.0_342]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:1.8.0_342]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:1.8.0_342]
	at java.lang.Thread.run(Thread.java:750) [?:1.8.0_342]
Caused by: java.lang.IllegalArgumentException: Cannot reflectively create enum objects
	at java.lang.reflect.Constructor.newInstance(Constructor.java:417) ~[?:1.8.0_342]
	at org.utbot.framework.concrete.MockValueConstructor.call(MockValueConstructor.kt:455) ~[main/:?]
	at org.utbot.framework.concrete.MockValueConstructor.updateWithExecutableCallModel(MockValueConstructor.kt:381) ~[main/:?]
	at org.utbot.framework.concrete.MockValueConstructor.constructFromAssembleModel(MockValueConstructor.kt:360) ~[main/:?]
	at org.utbot.framework.concrete.MockValueConstructor.construct(MockValueConstructor.kt:129) ~[main/:?]
	at org.utbot.framework.concrete.MockValueConstructor.value(MockValueConstructor.kt:435) ~[main/:?]
	at org.utbot.framework.concrete.MockValueConstructor.updateWithExecutableCallModel(MockValueConstructor.kt:377) ~[main/:?]
	at org.utbot.framework.concrete.MockValueConstructor.constructFromAssembleModel(MockValueConstructor.kt:360) ~[main/:?]
	at org.utbot.framework.concrete.MockValueConstructor.construct(MockValueConstructor.kt:129) ~[main/:?]
	at org.utbot.framework.concrete.MockValueConstructor.constructMethodParameters(MockValueConstructor.kt:104) ~[main/:?]
	at org.utbot.framework.concrete.UtExecutionInstrumentation.invoke(UtExecutionInstrumentation.kt:143) ~[main/:?]
	at org.utbot.framework.concrete.UtExecutionInstrumentation.invoke(UtExecutionInstrumentation.kt:106) ~[main/:?]
	at org.utbot.instrumentation.process.ChildProcessKt.loop(ChildProcess.kt:133) ~[main/:?]
	at org.utbot.instrumentation.process.ChildProcessKt.main(ChildProcess.kt:77) ~[main/:?]
	at org.utbot.instrumentation.process.ChildProcessKt.main(ChildProcess.kt) ~[main/:?]

Environment

The exact behavior of the contest estimator depends on its arguments, and on the enum handling code that is not currently in main (PR #611), but generally the exception should be reproduced even without enum patches.

Additional context

No additional context.

@korifey korifey moved this to Todo in UTBot Java Jul 30, 2022
@dtim dtim self-assigned this Jul 30, 2022
@dtim dtim added the ctg-bug Issue is a bug label Jul 30, 2022
@alisevych alisevych added this to the Release preparation milestone Sep 7, 2022
Repository owner moved this from Todo to Done in UTBot Java Sep 12, 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.

3 participants