EvoSuite / evosuite

EvoSuite - automated generation of JUnit test suites for Java classes
http://www.evosuite.org
GNU Lesser General Public License v3.0
829 stars 340 forks source link

evosuite exception "The thread is already executing unsafe code" #393

Open cinemamoon5 opened 2 years ago

cinemamoon5 commented 2 years ago

Context

When I was trying to analyze my Java project, following exception rises:

Full stack: java.lang.IllegalStateException: The thread is already executing unsafe code at org.evosuite.runtime.sandbox.MSecurityManager.goingToExecuteUnsafeCodeOnSameThread(MSecurityMa nager.java:243) at org.evosuite.runtime.sandbox.Sandbox.goingToExecuteUnsafeCodeOnSameThread(Sandbox.java:153) at org.evosuite.setup.TestClusterGenerator.initializeTargetMethods(TestClusterGenerator.java:613) at org.evosuite.setup.TestClusterGenerator.generateCluster(TestClusterGenerator.java:119) at org.evosuite.setup.DependencyAnalysis.analyze(DependencyAnalysis.java:120) at org.evosuite.setup.DependencyAnalysis.analyzeClass(DependencyAnalysis.java:136) at org.evosuite.junit.CoverageAnalysis.analyzeCoverage(CoverageAnalysis.java:114) at org.evosuite.rmi.service.ClientNodeImpl$2.run(ClientNodeImpl.java:422) at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515) at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) 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)

Does goingToExecuteUnsafeCodeOnSameThread() has a bug?

I think the implementation should be:

public void goingToExecuteUnsafeCodeOnSameThread() throws SecurityException, IllegalStateException { if (!privilegedThreads.contains(Thread.currentThread())) { throw new SecurityException("Current thread is not privileged"); } if (privilegedThreadToIgnore != null) { if(!Thread.currentThread().equals(privilegedThreadToIgnore)) { throw new IllegalStateException("The thread is already executing unsafe code"); } }else{ privilegedThreadToIgnore = Thread.currentThread(); } return; }

Since there are several calls of goingToExecuteUnsafeCodeOnSameThread() between outer goingToExecuteUnsafeCodeOnSameThread() and doneWithExecutingUnsafeCodeOnSameThread(), we should check if current thread is already privilegedThreadToIgnore.

is it right?