< prev index next >

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

Print this page
*** 1,7 ***
  /*
!  * Copyright (c) 2012, 2021, Oracle and/or its affiliates. All rights reserved.
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   *
   * This code is free software; you can redistribute it and/or modify it
   * under the terms of the GNU General Public License version 2 only, as
   * published by the Free Software Foundation.  Oracle designates this
--- 1,7 ---
  /*
!  * Copyright (c) 2012, 2022, Oracle and/or its affiliates. All rights reserved.
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   *
   * This code is free software; you can redistribute it and/or modify it
   * under the terms of the GNU General Public License version 2 only, as
   * published by the Free Software Foundation.  Oracle designates this

*** 23,15 ***
   * questions.
   */
  
  package java.lang.invoke;
  
  import java.security.*;
  import java.lang.reflect.*;
- import java.lang.invoke.MethodHandleNatives.Constants;
  import java.lang.invoke.MethodHandles.Lookup;
- import static java.lang.invoke.MethodHandleStatics.*;
  
  /*
   * Auxiliary to MethodHandleInfo, wants to nest in MethodHandleInfo but must be non-public.
   */
  /*non-public*/
--- 23,15 ---
   * questions.
   */
  
  package java.lang.invoke;
  
+ import jdk.internal.value.PrimitiveClass;
+ 
  import java.security.*;
  import java.lang.reflect.*;
  import java.lang.invoke.MethodHandles.Lookup;
  
  /*
   * Auxiliary to MethodHandleInfo, wants to nest in MethodHandleInfo but must be non-public.
   */
  /*non-public*/

*** 109,20 ***
  
      private Member reflectUnchecked() throws ReflectiveOperationException {
          byte refKind = (byte) getReferenceKind();
          Class<?> defc = getDeclaringClass();
          boolean isPublic = Modifier.isPublic(getModifiers());
!         if (MethodHandleNatives.refKindIsMethod(refKind)) {
              if (isPublic)
                  return defc.getMethod(getName(), getMethodType().parameterArray());
              else
                  return defc.getDeclaredMethod(getName(), getMethodType().parameterArray());
-         } else if (MethodHandleNatives.refKindIsConstructor(refKind)) {
-             if (isPublic)
-                 return defc.getConstructor(getMethodType().parameterArray());
-             else
-                 return defc.getDeclaredConstructor(getMethodType().parameterArray());
          } else if (MethodHandleNatives.refKindIsField(refKind)) {
              if (isPublic)
                  return defc.getField(getName());
              else
                  return defc.getDeclaredField(getName());
--- 109,35 ---
  
      private Member reflectUnchecked() throws ReflectiveOperationException {
          byte refKind = (byte) getReferenceKind();
          Class<?> defc = getDeclaringClass();
          boolean isPublic = Modifier.isPublic(getModifiers());
!         if (member.isObjectConstructor()) {
+             MethodType methodType = getMethodType();
+             if (MethodHandleNatives.refKindIsObjectConstructor(refKind) &&
+                     methodType.returnType() != void.class) {
+                 // object constructor
+                 throw new IllegalArgumentException("object constructor must be of void return type");
+             }
+             return isPublic ? defc.getConstructor(methodType.parameterArray())
+                             : defc.getDeclaredConstructor(methodType.parameterArray());
+         } else if (member.isStaticValueFactoryMethod()) {
+             assert defc.isValue();
+             MethodType methodType = getMethodType();
+             Class<?> rtype = PrimitiveClass.isPrimitiveClass(defc) ? PrimitiveClass.asValueType(defc) : defc;
+             if (MethodHandleNatives.refKindIsMethod(refKind) &&
+                     methodType.returnType() != rtype) {
+                 // static vnew factory
+                 throw new IllegalArgumentException("static factory must be of " + defc.getName());
+             }
+             return isPublic ? defc.getConstructor(methodType.parameterArray())
+                             : defc.getDeclaredConstructor(methodType.parameterArray());
+         } else if (MethodHandleNatives.refKindIsMethod(refKind)) {
              if (isPublic)
                  return defc.getMethod(getName(), getMethodType().parameterArray());
              else
                  return defc.getDeclaredMethod(getName(), getMethodType().parameterArray());
          } else if (MethodHandleNatives.refKindIsField(refKind)) {
              if (isPublic)
                  return defc.getField(getName());
              else
                  return defc.getDeclaredField(getName());
< prev index next >