< prev index next >

src/java.base/share/classes/java/lang/invoke/MethodHandles.java

Print this page
*** 2660,10 ***
--- 2660,12 ---
    ProcessBuilder.class, methodType(void.class, String[].class));
  ProcessBuilder pb = (ProcessBuilder)
    MH_newProcessBuilder.invoke("x", "y", "z");
  assertEquals("[x, y, z]", pb.command().toString());
           * }
+          *
+          *
           * @param refc the class or interface from which the method is accessed
           * @param type the type of the method, with the receiver argument omitted, and a void return type
           * @return the desired method handle
           * @throws NoSuchMethodException if the constructor does not exist
           * @throws IllegalAccessException if access checking fails

*** 2673,10 ***
--- 2675,13 ---
           */
          public MethodHandle findConstructor(Class<?> refc, MethodType type) throws NoSuchMethodException, IllegalAccessException {
              if (refc.isArray()) {
                  throw new NoSuchMethodException("no constructor for array class: " + refc.getName());
              }
+             if (type.returnType() != void.class) {
+                 throw new NoSuchMethodException("Constructors must have void return type: " + refc.getName());
+             }
              String name = ConstantDescs.INIT_NAME;
              MemberName ctor = resolveOrFail(REF_newInvokeSpecial, refc, name, type);
              return getDirectConstructor(refc, ctor);
          }
  

*** 3839,11 ***
          private MethodHandle getDirectMethodCommon(byte refKind, Class<?> refc, MemberName method,
                                                     boolean doRestrict,
                                                     Lookup boundCaller) throws IllegalAccessException {
              checkMethod(refKind, refc, method);
              assert(!method.isMethodHandleInvoke());
- 
              if (refKind == REF_invokeSpecial &&
                  refc != lookupClass() &&
                  !refc.isInterface() && !lookupClass().isInterface() &&
                  refc != lookupClass().getSuperclass() &&
                  refc.isAssignableFrom(lookupClass())) {
--- 3844,10 ---
< prev index next >