test/java/util/concurrent/FutureTask/Throw.java

Print this page

        

@@ -26,17 +26,29 @@
  * @bug 6415572
  * @summary Check exceptional behavior in run and done methods
  */
 
 import java.util.concurrent.*;
+import java.lang.reflect.Field;
+import sun.misc.Unsafe;
 
 public class Throw {
+    private static final Unsafe UNSAFE;
+    static {
+        try {
+            Field f = Unsafe.class.getDeclaredField("theUnsafe");
+            f.setAccessible(true);
+            UNSAFE = (Unsafe)f.get(null);
+        } catch (NoSuchFieldException | IllegalAccessException e) {
+            throw new RuntimeException(e);
+        }
+    }
 
     @SuppressWarnings("deprecation")
     static void THROW(final Throwable t) {
         if (t != null)
-            Thread.currentThread().stop(t);
+            UNSAFE.throwException(t);
     }
 
     Callable<Void> thrower(final Throwable t) {
         return new Callable<Void>() { public Void call() {
             THROW(t); return null; }};