test/java/util/concurrent/Executors/PrivilegedCallables.java

Print this page

        

@@ -31,12 +31,25 @@
 
 import java.util.concurrent.*;
 import java.util.*;
 import java.security.*;
 import static java.util.concurrent.Executors.*;
+import java.lang.reflect.Field;
+import sun.misc.Unsafe;
 
 public class PrivilegedCallables {
+    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);
+        }
+    }
+
     Callable<Integer> real;
 
     final Callable<Integer> realCaller = new Callable<Integer>() {
         public Integer call() throws Exception {
             return real.call(); }};

@@ -119,11 +132,11 @@
             if (rnd.nextBoolean()) {
                 final Throwable t = randomThrowable();
                 real = new Callable<Integer>() {
                     @SuppressWarnings("deprecation")
                     public Integer call() throws Exception {
-                        Thread.currentThread().stop(t);
+                        UNSAFE.throwException(t);
                         return null; }};
                 try {
                     c.call();
                     fail("Expected exception not thrown");
                 } catch (Throwable tt) { check(t == tt); }