jdk/test/java/lang/invoke/MethodHandlesTest.java
changeset 10080 eb387b9bb282
parent 10078 944d876457df
child 10081 0f7b9636aa64
equal deleted inserted replaced
10079:0ed5b8d18ae4 10080:eb387b9bb282
  2318                 System.out.println("Failed to throw");
  2318                 System.out.println("Failed to throw");
  2319                 assertTrue(false);
  2319                 assertTrue(false);
  2320             } catch (IllegalArgumentException ex) {
  2320             } catch (IllegalArgumentException ex) {
  2321             }
  2321             }
  2322         }
  2322         }
       
  2323     }
       
  2324 
       
  2325     @Test
       
  2326     public void testRunnableProxy() throws Throwable {
       
  2327         if (CAN_SKIP_WORKING)  return;
       
  2328         startTest("testRunnableProxy");
       
  2329         MethodHandles.Lookup lookup = MethodHandles.lookup();
       
  2330         MethodHandle run = lookup.findStatic(lookup.lookupClass(), "runForRunnable", MethodType.methodType(void.class));
       
  2331         Runnable r = MethodHandleProxies.asInterfaceInstance(Runnable.class, run);
       
  2332         testRunnableProxy(r);
       
  2333         assertCalled("runForRunnable");
       
  2334     }
       
  2335     private static void testRunnableProxy(Runnable r) {
       
  2336         //7058630: JSR 292 method handle proxy violates contract for Object methods
       
  2337         r.run();
       
  2338         Object o = r;
       
  2339         r = null;
       
  2340         boolean eq = (o == o);
       
  2341         int     hc = System.identityHashCode(o);
       
  2342         String  st = o.getClass().getName() + "@" + Integer.toHexString(hc);
       
  2343         Object expect = Arrays.asList(st, eq, hc);
       
  2344         if (verbosity >= 2)  System.out.println("expect st/eq/hc = "+expect);
       
  2345         Object actual = Arrays.asList(o.toString(), o.equals(o), o.hashCode());
       
  2346         if (verbosity >= 2)  System.out.println("actual st/eq/hc = "+actual);
       
  2347         assertEquals(expect, actual);
  2323     }
  2348     }
  2324 }
  2349 }
  2325 // Local abbreviated copy of sun.invoke.util.ValueConversions
  2350 // Local abbreviated copy of sun.invoke.util.ValueConversions
  2326 class ValueConversions {
  2351 class ValueConversions {
  2327     private static final Lookup IMPL_LOOKUP = MethodHandles.lookup();
  2352     private static final Lookup IMPL_LOOKUP = MethodHandles.lookup();