< prev index next >

src/java.base/share/classes/java/lang/constant/DirectMethodHandleDescImpl.java

Print this page
*** 61,20 ***
       * {@code kind} describes a constructor, and the return type of {@code type}
       * is not {@code void}
       * @jvms 4.2.2 Unqualified Names
       */
      DirectMethodHandleDescImpl(Kind kind, ClassDesc owner, String name, MethodTypeDesc type) {
!         if (kind == CONSTRUCTOR)
              name = "<init>";
  
          requireNonNull(kind);
          validateClassOrInterface(requireNonNull(owner));
          validateMemberName(requireNonNull(name), true);
          requireNonNull(type);
  
          switch (kind) {
!             case CONSTRUCTOR   -> validateConstructor(type);
              case GETTER        -> validateFieldType(type, false, true);
              case SETTER        -> validateFieldType(type, true, true);
              case STATIC_GETTER -> validateFieldType(type, false, false);
              case STATIC_SETTER -> validateFieldType(type, true, false);
          }
--- 61,21 ---
       * {@code kind} describes a constructor, and the return type of {@code type}
       * is not {@code void}
       * @jvms 4.2.2 Unqualified Names
       */
      DirectMethodHandleDescImpl(Kind kind, ClassDesc owner, String name, MethodTypeDesc type) {
!         if (kind == CONSTRUCTOR) {
              name = "<init>";
+         }
  
          requireNonNull(kind);
          validateClassOrInterface(requireNonNull(owner));
          validateMemberName(requireNonNull(name), true);
          requireNonNull(type);
  
          switch (kind) {
!             case CONSTRUCTOR   -> validateObjectConstructor(type);
              case GETTER        -> validateFieldType(type, false, true);
              case SETTER        -> validateFieldType(type, true, true);
              case STATIC_GETTER -> validateFieldType(type, false, false);
              case STATIC_SETTER -> validateFieldType(type, true, false);
          }

*** 100,11 ***
                                                  (isSetter ? "T" : ""), (isSetter ? "V" : "T"));
              throw new IllegalArgumentException(String.format("Expected type of %s for getter, found %s", expectedType, type));
          }
      }
  
!     private static void validateConstructor(MethodTypeDesc type) {
          if (!type.returnType().descriptorString().equals("V")) {
              throw new IllegalArgumentException(String.format("Expected type of (T*)V for constructor, found %s", type));
          }
      }
  
--- 101,11 ---
                                                  (isSetter ? "T" : ""), (isSetter ? "V" : "T"));
              throw new IllegalArgumentException(String.format("Expected type of %s for getter, found %s", expectedType, type));
          }
      }
  
!     private static void validateObjectConstructor(MethodTypeDesc type) {
          if (!type.returnType().descriptorString().equals("V")) {
              throw new IllegalArgumentException(String.format("Expected type of (T*)V for constructor, found %s", type));
          }
      }
  
< prev index next >