OSDN Git Service

Fix "run-test --jvm 067-preemptive-unpark"
authorBrian Carlstrom <bdc@google.com>
Wed, 3 Jun 2015 04:53:14 +0000 (21:53 -0700)
committerBrian Carlstrom <bdc@google.com>
Wed, 3 Jun 2015 04:53:14 +0000 (21:53 -0700)
Change-Id: I3afd86510091354d79fbb008e9670940d71a0721

test/067-preemptive-unpark/src/Main.java

index 2c099b9..beb3262 100644 (file)
@@ -40,22 +40,24 @@ public class Main {
     /**
      * Set up {@link #UNSAFE}.
      */
-    public static void setUp() {
+    public static void setUp() throws Exception{
         /*
          * Subvert the access check to get the unique Unsafe instance.
          * We can do this because there's no security manager
          * installed when running the test.
          */
+        Field field = null;
         try {
-            Field field = Unsafe.class.getDeclaredField("THE_ONE");
-            field.setAccessible(true);
-
-            UNSAFE = (Unsafe) field.get(null);
-        } catch (NoSuchFieldException ex) {
-            throw new RuntimeException(ex);
-        } catch (IllegalAccessException ex) {
-            throw new RuntimeException(ex);
+            field = Unsafe.class.getDeclaredField("THE_ONE");
+        } catch (NoSuchFieldException e1) {
+            try {
+                field = Unsafe.class.getDeclaredField("theUnsafe");
+            } catch (NoSuchFieldException e2) {
+                throw new RuntimeException("Failed to find THE_ONE or theUnsafe");
+            }
         }
+        field.setAccessible(true);
+        UNSAFE = (Unsafe) field.get(null);
     }
 
     /**