1 /*
   2  * @test /nodynamiccopyright/
   3  * @summary warn if a class or member is not found at compile time
   4  * @compile/fail/ref=WarningIfClassOrMemberNotFound.out -Werror -XDrawDiagnostics WarningIfClassOrMemberNotFound.java
   5  */
   6 
   7 import java.lang.invoke.*; import java.lang.constant.*;
   8 import static java.lang.invoke.Intrinsics.*;
   9 
  10 class WarningIfClassOrMemberNotFound {
  11     void m() {
  12         final MethodTypeDesc mt1 = MethodTypeDesc.of(ClassDesc.ofDescriptor("Ljava/lang/String;"));
  13         MethodHandle mh1 = ldc(MethodHandleDesc.of(DirectMethodHandleDesc.Kind.STATIC, ClassDesc.ofDescriptor("LNonExistentClass1;"), "foo", mt1));
  14 
  15         ClassDesc cr = ClassDesc.ofDescriptor("LNonExistentClass2;");
  16         Class<?> c = ldc(cr);
  17 
  18         ClassDesc crArr = ClassDesc.ofDescriptor("[[[LNonExistentClass3;");
  19         Class<?> cArr = ldc(crArr);
  20 
  21         final MethodTypeDesc mt2 = MethodTypeDesc.of(ClassDesc.ofDescriptor("Ljava/lang/String;"));
  22         // now the class exists but the method doesn't
  23         MethodHandle mh2 = ldc(MethodHandleDesc.of(DirectMethodHandleDesc.Kind.STATIC, ClassDesc.ofDescriptor("LWarningIfClassOrMemberNotFound;"), "bar", mt2));
  24 
  25         final MethodTypeDesc mt3 = MethodTypeDesc.of(ClassDesc.ofDescriptor("Ljava/lang/String;"));
  26         // now the class exists and so is the method but the arguments are incorrect
  27         MethodHandle mh3 = ldc(MethodHandleDesc.of(DirectMethodHandleDesc.Kind.STATIC, ClassDesc.ofDescriptor("LWarningIfClassOrMemberNotFound;"), "foo", mt3));
  28     }
  29 
  30     String foo(String s) { return s; }
  31 }