Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8344203

java.lang.classfile.Attribute attributeName() method should return Utf8Entry

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P4 P4
    • 24
    • core-libs
    • None
    • source
    • minimal
    • Changes to preview APIs have minimal compatibility risk.
    • Java API
    • SE

      Summary

      Change java.lang.classfile.Attribute::attributeName method return type from String to java.lang.classfile.constantpool.Utf8Entry.

      Problem

      Class-File API usually expose names in a form of java.lang.classfile.constantpool.Utf8Entry. Unfortunately java.lang.classfile.Attribute::attributeName method was omitted during the API review and it returns inflated String value of the name.

      Solution

      Change java.lang.classfile.Attribute::attributeName method return type from String to java.lang.classfile.constantpool.Utf8Entry.

      Specification

      diff --git a/src/java.base/share/classes/java/lang/classfile/Attribute.java b/src/java.base/share/classes/java/lang/classfile/Attribute.java
      index e2f0072d3967f..2d559552684a1 100644
      --- a/src/java.base/share/classes/java/lang/classfile/Attribute.java
      +++ b/src/java.base/share/classes/java/lang/classfile/Attribute.java
      @@ -25,6 +25,7 @@
       package java.lang.classfile;
      
       import java.lang.classfile.attribute.*;
      +import java.lang.classfile.constantpool.Utf8Entry;
      
       import jdk.internal.classfile.impl.BoundAttribute;
       import jdk.internal.classfile.impl.UnboundAttribute;
      @@ -65,7 +66,7 @@ public sealed interface Attribute<A extends Attribute<A>>
           /**
            * {@return the name of the attribute}
            */
      -    String attributeName();
      +    Utf8Entry attributeName();
      
           /**
            * {@return the {@link AttributeMapper} associated with this attribute}
      diff --git a/src/java.base/share/classes/java/lang/classfile/CustomAttribute.java b/src/java.base/share/classes/java/lang/classfile/CustomAttribute.java
      index 9fe492dc22c4c..6c3a0de2b7af3 100644
      --- a/src/java.base/share/classes/java/lang/classfile/CustomAttribute.java
      +++ b/src/java.base/share/classes/java/lang/classfile/CustomAttribute.java
      @@ -24,6 +24,8 @@
        */
       package java.lang.classfile;
      
      +import java.lang.classfile.constantpool.Utf8Entry;
      +import jdk.internal.classfile.impl.TemporaryConstantPool;
       import jdk.internal.javac.PreviewFeature;
      
       /**
      @@ -55,8 +57,8 @@ public final AttributeMapper<T> attributeMapper() {
           }
      
           @Override
      -    public final String attributeName() {
      -        return mapper.name();
      +    public Utf8Entry attributeName() {
      +        return TemporaryConstantPool.INSTANCE.utf8Entry(mapper.name());
           }
      
           @Override

            asotona Adam Sotona
            webbuggrp Webbug Group
            Chen Liang
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: