methodHandleEntry() for Map$Entry::getKey

Michael van Acken michael.van.acken at gmail.com
Thu Aug 18 08:53:47 UTC 2022


Putting a method handle for getKey into the constant pool got me

   #9 = NameAndType        #7:#8          //
getKey:(Ljava/util/Map$Entry;)Ljava/lang/Object;
  #10 = Methodref          #6.#9          //
java/util/Map$Entry.getKey:(Ljava/util/Map$Entry;)Ljava/lang/Object;
  #11 = MethodHandle       9:#10          // REF_invokeInterface
java/util/Map$Entry.getKey:(Ljava/util/Map$Entry;)Ljava/lang/Object;

instead of the expected

  #33 = NameAndType        #7:#32         // getKey:()Ljava/lang/Object;
  #34 = InterfaceMethodref #6.#33         //
java/util/Map$Entry.getKey:()Ljava/lang/Object;

That is, both tag and lookup type are off target.

The attached patch allows me to continue for now.  The
MTD -> String -> MTD conversion is a bit heavy handed.

-- mva



diff --git
a/src/java.base/share/classes/jdk/classfile/constantpool/ConstantPoolBuilder.java
b/src/java.base/share/classes/jdk/classfile/constantpool/ConstantPoolBuilder.java
index 1363f1e8c83..7c3395d0c55 100755
---
a/src/java.base/share/classes/jdk/classfile/constantpool/ConstantPoolBuilder.java
+++
b/src/java.base/share/classes/jdk/classfile/constantpool/ConstantPoolBuilder.java
@@ -346,7 +346,11 @@ public sealed interface ConstantPoolBuilder
      * @param descriptor the symbolic descriptor of the method handle
      */
     default MethodHandleEntry methodHandleEntry(DirectMethodHandleDesc
descriptor) {
-        return methodHandleEntry(descriptor.refKind(),
methodRefEntry(descriptor.owner(), descriptor.methodName(),
descriptor.invocationType()));
+        var lookupType =
MethodTypeDesc.ofDescriptor(descriptor.lookupDescriptor());
+        return methodHandleEntry(descriptor.refKind(),
+                                 descriptor.isOwnerInterface() ?
+
interfaceMethodRefEntry(descriptor.owner(), descriptor.methodName(),
lookupType) :
+                                 methodRefEntry(descriptor.owner(),
descriptor.methodName(), lookupType));
     }

     /**
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/classfile-api-dev/attachments/20220818/7b54467f/attachment.htm>


More information about the classfile-api-dev mailing list