--- jsr166/src/jsr166y/ConcurrentLinkedDeque.java 2011/06/01 21:04:30 1.2 +++ jsr166/src/jsr166y/ConcurrentLinkedDeque.java 2013/01/09 02:51:37 1.5 @@ -61,7 +61,6 @@ import java.util.Queue; * @author Martin Buchholz * @param the type of elements held in this collection */ - public class ConcurrentLinkedDeque extends AbstractCollection implements Deque, java.io.Serializable { @@ -1221,8 +1220,7 @@ public class ConcurrentLinkedDeque * The following code can be used to dump the deque into a newly * allocated array of {@code String}: * - *
-     *     String[] y = x.toArray(new String[0]);
+ *
 {@code String[] y = x.toArray(new String[0]);}
* * Note that {@code toArray(new Object[0])} is identical in function to * {@code toArray()}. @@ -1448,22 +1446,23 @@ public class ConcurrentLinkedDeque static sun.misc.Unsafe getUnsafe() { try { return sun.misc.Unsafe.getUnsafe(); - } catch (SecurityException se) { - try { - return java.security.AccessController.doPrivileged - (new java.security - .PrivilegedExceptionAction() { - public sun.misc.Unsafe run() throws Exception { - java.lang.reflect.Field f = sun.misc - .Unsafe.class.getDeclaredField("theUnsafe"); - f.setAccessible(true); - return (sun.misc.Unsafe) f.get(null); - }}); - } catch (java.security.PrivilegedActionException e) { - throw new RuntimeException("Could not initialize intrinsics", - e.getCause()); - } + } catch (SecurityException tryReflectionInstead) {} + try { + return java.security.AccessController.doPrivileged + (new java.security.PrivilegedExceptionAction() { + public sun.misc.Unsafe run() throws Exception { + Class k = sun.misc.Unsafe.class; + for (java.lang.reflect.Field f : k.getDeclaredFields()) { + f.setAccessible(true); + Object x = f.get(null); + if (k.isInstance(x)) + return k.cast(x); + } + throw new NoSuchFieldError("the Unsafe"); + }}); + } catch (java.security.PrivilegedActionException e) { + throw new RuntimeException("Could not initialize intrinsics", + e.getCause()); } } - }