Skip to content

Commit

Permalink
Terminate the thread when unhandled exception happens. (#476)
Browse files Browse the repository at this point in the history
  • Loading branch information
aoli-al authored Jul 17, 2024
1 parent 8d0e295 commit 6233e3b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
8 changes: 2 additions & 6 deletions src/main/gov/nasa/jpf/vm/ThreadInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -2881,14 +2881,10 @@ public Instruction throwException (int exceptionObjRef) {

// there was no overridden uncaughtHandler, or we already executed it
if ("java.lang.ThreadDeath".equals(exceptionName)) { // gracefully shut down
unwindToFirstFrame();
pendingException = null;
return top.getPC().getNext(); // the final DIRECTCALLRETURN

} else { // we have a NoUncaughtPropertyViolation
//NoUncaughtExceptionsProperty.setExceptionInfo(pendingException);
throw new UncaughtException(this, exceptionObjRef);
}
unwindToFirstFrame();
return top.getPC().getNext(); // the final DIRECTCALLRETURN

} else { // we found a matching handler

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package gov.nasa.jpf.test.java.concurrent;

import gov.nasa.jpf.util.test.TestJPF;
import org.junit.Test;

public class ThreadExceptionTest extends TestJPF {
@Test
public void testResourceAcquisition() {
if (verifyUnhandledException("java.lang.RuntimeException",
"+search.class=gov.nasa.jpf.search.RandomSearch",
"+cg.randomize_choices=FIXED_SEED", "+search.RandomSearch.path_limit=10", "+search.multiple_errors=true")) {
Thread t = new Thread(() -> {
throw new RuntimeException("Exception from thread");
});
t.start();
}
}
}

0 comments on commit 6233e3b

Please sign in to comment.