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

Print this page

        

*** 31,42 **** --- 31,55 ---- 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,129 **** if (rnd.nextBoolean()) { final Throwable t = randomThrowable(); real = new Callable<Integer>() { @SuppressWarnings("deprecation") public Integer call() throws Exception { ! Thread.currentThread().stop(t); return null; }}; try { c.call(); fail("Expected exception not thrown"); } catch (Throwable tt) { check(t == tt); } --- 132,142 ---- if (rnd.nextBoolean()) { final Throwable t = randomThrowable(); real = new Callable<Integer>() { @SuppressWarnings("deprecation") public Integer call() throws Exception { ! UNSAFE.throwException(t); return null; }}; try { c.call(); fail("Expected exception not thrown"); } catch (Throwable tt) { check(t == tt); }