jdk/test/java/lang/invoke/RevealDirectTest.java
changeset 20535 cc85c8626435
parent 19804 83170920c07b
child 21596 0e3a39f29dbc
equal deleted inserted replaced
20534:da86f7904e6d 20535:cc85c8626435
   102         }
   102         }
   103         Simple() { finalField = -NICE_CONSTANT; }
   103         Simple() { finalField = -NICE_CONSTANT; }
   104         private static Lookup localLookup() { return lookup(); }
   104         private static Lookup localLookup() { return lookup(); }
   105         private static List<Member> members() { return getMembers(lookup().lookupClass()); };
   105         private static List<Member> members() { return getMembers(lookup().lookupClass()); };
   106     }
   106     }
       
   107     static class Nestmate {
       
   108         private static Lookup localLookup() { return lookup(); }
       
   109     }
   107 
   110 
   108     static boolean VERBOSE = false;
   111     static boolean VERBOSE = false;
   109 
   112 
   110     @Test public void testSimple() throws Throwable {
   113     @Test public void testSimple() throws Throwable {
   111         if (VERBOSE)  System.out.println("@Test testSimple");
   114         if (VERBOSE)  System.out.println("@Test testSimple");
   150         List<Member> mems = union(getMembers(MethodHandles.class, "lookup"),
   153         List<Member> mems = union(getMembers(MethodHandles.class, "lookup"),
   151                                   getMembers(Class.class, "forName"),
   154                                   getMembers(Class.class, "forName"),
   152                                   getMembers(Method.class, "invoke"));
   155                                   getMembers(Method.class, "invoke"));
   153         mems = callerSensitive(true, publicOnly(mems));
   156         mems = callerSensitive(true, publicOnly(mems));
   154         // CS methods cannot be looked up with publicLookup
   157         // CS methods cannot be looked up with publicLookup
   155         testOnMembersNoLookup("testCallerSensitiveNegative", mems, publicLookup());
   158         testOnMembersNoLookup("testCallerSensitiveNegative/1", mems, publicLookup());
       
   159         // CS methods have to be revealed with a matching lookupClass
       
   160         testOnMembersNoReveal("testCallerSensitiveNegative/2", mems, Simple.localLookup(), publicLookup());
       
   161         testOnMembersNoReveal("testCallerSensitiveNegative/3", mems, Simple.localLookup(), Nestmate.localLookup());
   156     }
   162     }
   157     @Test public void testMethodHandleNatives() throws Throwable {
   163     @Test public void testMethodHandleNatives() throws Throwable {
   158         if (VERBOSE)  System.out.println("@Test testMethodHandleNatives");
   164         if (VERBOSE)  System.out.println("@Test testMethodHandleNatives");
   159         List<Member> mems = getMembers(MethodHandle.class, "invoke", "invokeExact");
   165         List<Member> mems = getMembers(MethodHandle.class, "invoke", "invokeExact");
   160         testOnMembers("testMethodHandleNatives", mems, Simple.localLookup());
   166         testOnMembers("testMethodHandleNatives", mems, Simple.localLookup());
   701             }
   707             }
   702             MethodHandleInfo info;
   708             MethodHandleInfo info;
   703             try {
   709             try {
   704                 info = revLookup.revealDirect(mh);
   710                 info = revLookup.revealDirect(mh);
   705                 if (expectEx2)  throw new AssertionError("unexpected revelation for negative test");
   711                 if (expectEx2)  throw new AssertionError("unexpected revelation for negative test");
   706             } catch (Throwable ex2) {
   712             } catch (IllegalArgumentException|SecurityException ex2) {
   707                 if (VERBOSE)  System.out.println("  "+variation+": "+res+" => "+mh.getClass().getName()+" => (EX2)"+ex2);
   713                 if (VERBOSE)  System.out.println("  "+variation+": "+res+" => "+mh.getClass().getName()+" => (EX2)"+ex2);
   708                 if (expectEx2)
   714                 if (expectEx2)
   709                     continue;  // this is OK; we expected the reflect to fail
   715                     continue;  // this is OK; we expected the reflect to fail
   710                 if (failureMode != NO_FAIL)
   716                 if (failureMode != NO_FAIL)
   711                     throw new AssertionError("unexpected revelation failure for negative test", ex2);
   717                     throw new AssertionError("unexpected revelation failure for negative test", ex2);