methodHandleEntry() for Map$Entry::getKey

Adam Sotona adam.sotona at oracle.com
Thu Aug 18 10:14:57 UTC 2022


Thanks for the report.
It should be fixed now:
https://github.com/openjdk/jdk-sandbox/commit/de17a3b0eb7c80935d701ba98014f2bd35c221b5

Thanks,
Adam

From: classfile-api-dev <classfile-api-dev-retn at openjdk.org> on behalf of Michael van Acken <michael.van.acken at gmail.com>
Date: Thursday, 18 August 2022 10:54
To: classfile-api-dev at openjdk.org <classfile-api-dev at openjdk.org>
Subject: methodHandleEntry() for Map$Entry::getKey
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/b4252c5c/attachment-0001.htm>


More information about the classfile-api-dev mailing list