Skip to content

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

Closed
@dtim

Description

@dtim

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.

Metadata

Metadata

Labels

ctg-bugIssue is a bug

Type

No type

Projects

Status

Done

Relationships

None yet

Development

No branches or pull requests

Issue actions