From ba39321902400e103cdce0b326d0005123b1d87e Mon Sep 17 00:00:00 2001 From: Adam Sotona Date: Fri, 15 Nov 2024 11:40:15 +0000 Subject: [PATCH] 8343881: java.lang.classfile.Attribute attributeName() method should return Utf8Entry Reviewed-by: liach --- .../java/lang/classfile/Attribute.java | 3 +- .../java/lang/classfile/CustomAttribute.java | 6 +- .../impl/AbstractAttributeMapper.java | 2 +- .../classfile/impl/BoundAttribute.java | 8 +- .../classfile/impl/ClassPrinterImpl.java | 10 +- .../classfile/impl/DirectCodeBuilder.java | 25 ++ .../classfile/impl/SplitConstantPool.java | 5 + .../classfile/impl/StackMapGenerator.java | 6 + .../classfile/impl/UnboundAttribute.java | 282 +++++++++++++++++- .../jdk/internal/classfile/impl/Util.java | 5 + .../impl/verifier/ParserVerifier.java | 6 +- .../com/sun/tools/javap/AttributeWriter.java | 2 +- .../jdk/jdk/classfile/BoundAttributeTest.java | 6 + test/jdk/jdk/classfile/CorpusTest.java | 15 + test/jdk/jdk/classfile/LimitsTest.java | 26 +- .../jdk/classfile/LowJCovAttributeTest.java | 2 +- test/jdk/jdk/classfile/LowModuleTest.java | 2 +- test/jdk/jdk/classfile/VerifierSelfTest.java | 11 +- .../jdk/classfile/helpers/ClassRecord.java | 2 +- .../helpers/RebuildingTransformation.java | 16 +- .../AnnotationDefaultTest.java | 2 +- .../EnclosingMethod/EnclosingMethodTest.java | 2 +- .../LineNumberTable/LineNumberTestBase.java | 2 +- .../attributes/Signature/Driver.java | 2 +- .../SourceFile/SourceFileTestBase.java | 2 +- .../attributes/deprecated/DeprecatedTest.java | 2 +- .../innerclasses/InnerClassesTestBase.java | 2 +- .../sealed/CheckSubtypesOfSealedTest.java | 4 +- test/langtools/tools/javap/T6716452.java | 2 +- 29 files changed, 415 insertions(+), 45 deletions(-) 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 e2f0072d396..2d559552684 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> /** * {@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 9fe492dc22c..6c3a0de2b7a 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 abstract non-sealed class CustomAttribute> } @Override - public final String attributeName() { - return mapper.name(); + public Utf8Entry attributeName() { + return TemporaryConstantPool.INSTANCE.utf8Entry(mapper.name()); } @Override diff --git a/src/java.base/share/classes/jdk/internal/classfile/impl/AbstractAttributeMapper.java b/src/java.base/share/classes/jdk/internal/classfile/impl/AbstractAttributeMapper.java index b29b9f6f955..648582b8a7d 100644 --- a/src/java.base/share/classes/jdk/internal/classfile/impl/AbstractAttributeMapper.java +++ b/src/java.base/share/classes/jdk/internal/classfile/impl/AbstractAttributeMapper.java @@ -64,7 +64,7 @@ public sealed abstract class AbstractAttributeMapper> @Override public final void writeAttribute(BufWriter writer, T attr) { BufWriterImpl buf = (BufWriterImpl) writer; - buf.writeIndex(buf.constantPool().utf8Entry(name)); + buf.writeIndex(attr.attributeName()); int lengthIndex = buf.skip(4); writeBody(buf, attr); int written = buf.size() - lengthIndex - 4; diff --git a/src/java.base/share/classes/jdk/internal/classfile/impl/BoundAttribute.java b/src/java.base/share/classes/jdk/internal/classfile/impl/BoundAttribute.java index 59a2b03c91e..114101b02e5 100644 --- a/src/java.base/share/classes/jdk/internal/classfile/impl/BoundAttribute.java +++ b/src/java.base/share/classes/jdk/internal/classfile/impl/BoundAttribute.java @@ -47,6 +47,7 @@ public abstract sealed class BoundAttribute> private final AttributeMapper mapper; final ClassReaderImpl classReader; final int payloadStart; + Utf8Entry name; BoundAttribute(ClassReader classReader, AttributeMapper mapper, int payloadStart) { this.mapper = mapper; @@ -59,8 +60,11 @@ public abstract sealed class BoundAttribute> } @Override - public String attributeName() { - return mapper.name(); + public Utf8Entry attributeName() { + if (name == null) { + name = classReader.readEntry(payloadStart - 6, Utf8Entry.class); + } + return name; } @Override diff --git a/src/java.base/share/classes/jdk/internal/classfile/impl/ClassPrinterImpl.java b/src/java.base/share/classes/jdk/internal/classfile/impl/ClassPrinterImpl.java index b8fce2fd288..1ded017f2a2 100644 --- a/src/java.base/share/classes/jdk/internal/classfile/impl/ClassPrinterImpl.java +++ b/src/java.base/share/classes/jdk/internal/classfile/impl/ClassPrinterImpl.java @@ -574,7 +574,7 @@ public final class ClassPrinterImpl { list("flags", "flag", clm.flags().flags().stream().map(AccessFlag::name)), leaf("superclass", clm.superclass().map(ClassEntry::asInternalName).orElse("")), list("interfaces", "interface", clm.interfaces().stream().map(ClassEntry::asInternalName)), - list("attributes", "attribute", clm.attributes().stream().map(Attribute::attributeName))) + list("attributes", "attribute", clm.attributes().stream().map(Attribute::attributeName).map(Utf8Entry::stringValue))) .with(constantPoolToTree(clm.constantPool(), verbosity)) .with(attributesToTree(clm.attributes(), verbosity)) .with(new ListNodeImpl(BLOCK, "fields", clm.fields().stream().map(f -> @@ -672,7 +672,7 @@ public final class ClassPrinterImpl { "flag", f.flags().flags().stream().map(AccessFlag::name)), leaf("field type", f.fieldType().stringValue()), list("attributes", - "attribute", f.attributes().stream().map(Attribute::attributeName))) + "attribute", f.attributes().stream().map(Attribute::attributeName).map(Utf8Entry::stringValue))) .with(attributesToTree(f.attributes(), verbosity)); } @@ -683,7 +683,7 @@ public final class ClassPrinterImpl { "flag", m.flags().flags().stream().map(AccessFlag::name)), leaf("method type", m.methodType().stringValue()), list("attributes", - "attribute", m.attributes().stream().map(Attribute::attributeName))) + "attribute", m.attributes().stream().map(Attribute::attributeName).map(Utf8Entry::stringValue))) .with(attributesToTree(m.attributes(), verbosity)) .with(codeToTree((CodeAttribute)m.code().orElse(null), verbosity)); } @@ -694,7 +694,7 @@ public final class ClassPrinterImpl { codeNode.with(leaf("max stack", com.maxStack())); codeNode.with(leaf("max locals", com.maxLocals())); codeNode.with(list("attributes", - "attribute", com.attributes().stream().map(Attribute::attributeName))); + "attribute", com.attributes().stream().map(Attribute::attributeName).map(Utf8Entry::stringValue))); var stackMap = new MapNodeImpl(BLOCK, "stack map frames"); var visibleTypeAnnos = new LinkedHashMap>(); var invisibleTypeAnnos = new LinkedHashMap>(); @@ -996,7 +996,7 @@ public final class ClassPrinterImpl { "name", rc.name().stringValue(), "type", rc.descriptor().stringValue())) .with(list("attributes", "attribute", rc.attributes().stream() - .map(Attribute::attributeName))) + .map(Attribute::attributeName).map(Utf8Entry::stringValue))) .with(attributesToTree(rc.attributes(), verbosity))))); case AnnotationDefaultAttribute ada -> nodes.add(new MapNodeImpl(FLOW, "annotation default").with(elementValueToTree(ada.defaultValue()))); diff --git a/src/java.base/share/classes/jdk/internal/classfile/impl/DirectCodeBuilder.java b/src/java.base/share/classes/jdk/internal/classfile/impl/DirectCodeBuilder.java index 7d554a35974..5093f6408c8 100644 --- a/src/java.base/share/classes/jdk/internal/classfile/impl/DirectCodeBuilder.java +++ b/src/java.base/share/classes/jdk/internal/classfile/impl/DirectCodeBuilder.java @@ -241,6 +241,11 @@ public final class DirectCodeBuilder if (crSize < characterRangesCount) b.patchU2(pos, crSize); } + + @Override + public Utf8Entry attributeName() { + return constantPool.utf8Entry(Attributes.NAME_CHARACTER_RANGE_TABLE); + } }; attributes.withAttribute(a); } @@ -265,6 +270,11 @@ public final class DirectCodeBuilder if (lvSize < localVariablesCount) b.patchU2(pos, lvSize); } + + @Override + public Utf8Entry attributeName() { + return constantPool.utf8Entry(Attributes.NAME_LOCAL_VARIABLE_TABLE); + } }; attributes.withAttribute(a); } @@ -289,6 +299,11 @@ public final class DirectCodeBuilder if (lvtSize < localVariableTypesCount) b.patchU2(pos, lvtSize); } + + @Override + public Utf8Entry attributeName() { + return constantPool.utf8Entry(Attributes.NAME_LOCAL_VARIABLE_TYPE_TABLE); + } }; attributes.withAttribute(a); } @@ -371,6 +386,11 @@ public final class DirectCodeBuilder dcb.attributes.writeTo(buf); buf.setLabelContext(null); } + + @Override + public Utf8Entry attributeName() { + return constantPool.utf8Entry(Attributes.NAME_CODE); + } }; } @@ -416,6 +436,11 @@ public final class DirectCodeBuilder b.writeU2(buf.size() / 4); b.writeBytes(buf); } + + @Override + public Utf8Entry attributeName() { + return buf.constantPool().utf8Entry(Attributes.NAME_LINE_NUMBER_TABLE); + } } private boolean codeAndExceptionsMatch(int codeLength) { diff --git a/src/java.base/share/classes/jdk/internal/classfile/impl/SplitConstantPool.java b/src/java.base/share/classes/jdk/internal/classfile/impl/SplitConstantPool.java index 0e26a8941e0..5ba81fc2927 100644 --- a/src/java.base/share/classes/jdk/internal/classfile/impl/SplitConstantPool.java +++ b/src/java.base/share/classes/jdk/internal/classfile/impl/SplitConstantPool.java @@ -146,6 +146,11 @@ public final class SplitConstantPool implements ConstantPoolBuilder { for (int i = 0; i < bsmSize; i++) bootstrapMethodEntry(i).writeTo(buf); } + + @Override + public Utf8Entry attributeName() { + return utf8Entry(Attributes.NAME_BOOTSTRAP_METHODS); + } }; a.writeTo(buf); } diff --git a/src/java.base/share/classes/jdk/internal/classfile/impl/StackMapGenerator.java b/src/java.base/share/classes/jdk/internal/classfile/impl/StackMapGenerator.java index a83c32dc05a..7e16aea5a52 100644 --- a/src/java.base/share/classes/jdk/internal/classfile/impl/StackMapGenerator.java +++ b/src/java.base/share/classes/jdk/internal/classfile/impl/StackMapGenerator.java @@ -35,6 +35,7 @@ import java.lang.classfile.constantpool.ConstantDynamicEntry; import java.lang.classfile.constantpool.ConstantPoolBuilder; import java.lang.classfile.constantpool.InvokeDynamicEntry; import java.lang.classfile.constantpool.MemberRefEntry; +import java.lang.classfile.constantpool.Utf8Entry; import java.lang.constant.ClassDesc; import java.lang.constant.MethodTypeDesc; import java.util.ArrayList; @@ -401,6 +402,11 @@ public final class StackMapGenerator { prevFrame = fr; } } + + @Override + public Utf8Entry attributeName() { + return cp.utf8Entry(Attributes.NAME_STACK_MAP_TABLE); + } }; } diff --git a/src/java.base/share/classes/jdk/internal/classfile/impl/UnboundAttribute.java b/src/java.base/share/classes/jdk/internal/classfile/impl/UnboundAttribute.java index dfad66a897c..0b0f1836f66 100644 --- a/src/java.base/share/classes/jdk/internal/classfile/impl/UnboundAttribute.java +++ b/src/java.base/share/classes/jdk/internal/classfile/impl/UnboundAttribute.java @@ -54,11 +54,6 @@ public abstract sealed class UnboundAttribute> return mapper; } - @Override - public String attributeName() { - return mapper.name(); - } - @Override @SuppressWarnings("unchecked") public void writeTo(BufWriterImpl buf) { @@ -93,6 +88,8 @@ public abstract sealed class UnboundAttribute> extends UnboundAttribute implements ConstantValueAttribute { + private static final Utf8Entry NAME = TemporaryConstantPool.INSTANCE.utf8Entry(Attributes.NAME_CONSTANT_VALUE); + private final ConstantValueEntry entry; public UnboundConstantValueAttribute(ConstantValueEntry entry) { @@ -105,27 +102,50 @@ public abstract sealed class UnboundAttribute> return entry; } + @Override + public Utf8Entry attributeName() { + return NAME; + } } public static final class UnboundDeprecatedAttribute extends UnboundAttribute implements DeprecatedAttribute { + + private static final Utf8Entry NAME = TemporaryConstantPool.INSTANCE.utf8Entry(Attributes.NAME_DEPRECATED); + public UnboundDeprecatedAttribute() { super(Attributes.deprecated()); } + + @Override + public Utf8Entry attributeName() { + return NAME; + } } public static final class UnboundSyntheticAttribute extends UnboundAttribute implements SyntheticAttribute { + + private static final Utf8Entry NAME = TemporaryConstantPool.INSTANCE.utf8Entry(Attributes.NAME_SYNTHETIC); + public UnboundSyntheticAttribute() { super(Attributes.synthetic()); } + + @Override + public Utf8Entry attributeName() { + return NAME; + } } public static final class UnboundSignatureAttribute extends UnboundAttribute implements SignatureAttribute { + + private static final Utf8Entry NAME = TemporaryConstantPool.INSTANCE.utf8Entry(Attributes.NAME_SIGNATURE); + private final Utf8Entry signature; public UnboundSignatureAttribute(Utf8Entry signature) { @@ -137,11 +157,19 @@ public abstract sealed class UnboundAttribute> public Utf8Entry signature() { return signature; } + + @Override + public Utf8Entry attributeName() { + return NAME; + } } public static final class UnboundExceptionsAttribute extends UnboundAttribute implements ExceptionsAttribute { + + private static final Utf8Entry NAME = TemporaryConstantPool.INSTANCE.utf8Entry(Attributes.NAME_EXCEPTIONS); + private final List exceptions; public UnboundExceptionsAttribute(List exceptions) { @@ -153,11 +181,19 @@ public abstract sealed class UnboundAttribute> public List exceptions() { return exceptions; } + + @Override + public Utf8Entry attributeName() { + return NAME; + } } public static final class UnboundAnnotationDefaultAttribute extends UnboundAttribute implements AnnotationDefaultAttribute { + + private static final Utf8Entry NAME = TemporaryConstantPool.INSTANCE.utf8Entry(Attributes.NAME_ANNOTATION_DEFAULT); + private final AnnotationValue annotationDefault; public UnboundAnnotationDefaultAttribute(AnnotationValue annotationDefault) { @@ -169,10 +205,18 @@ public abstract sealed class UnboundAttribute> public AnnotationValue defaultValue() { return annotationDefault; } + + @Override + public Utf8Entry attributeName() { + return NAME; + } } public static final class UnboundSourceFileAttribute extends UnboundAttribute implements SourceFileAttribute { + + private static final Utf8Entry NAME = TemporaryConstantPool.INSTANCE.utf8Entry(Attributes.NAME_SOURCE_FILE); + private final Utf8Entry sourceFile; public UnboundSourceFileAttribute(Utf8Entry sourceFile) { @@ -185,10 +229,17 @@ public abstract sealed class UnboundAttribute> return sourceFile; } + @Override + public Utf8Entry attributeName() { + return NAME; + } } public static final class UnboundStackMapTableAttribute extends UnboundAttribute implements StackMapTableAttribute { + + private static final Utf8Entry NAME = TemporaryConstantPool.INSTANCE.utf8Entry(Attributes.NAME_STACK_MAP_TABLE); + private final List entries; public UnboundStackMapTableAttribute(List entries) { @@ -200,11 +251,19 @@ public abstract sealed class UnboundAttribute> public List entries() { return entries; } + + @Override + public Utf8Entry attributeName() { + return NAME; + } } public static final class UnboundInnerClassesAttribute extends UnboundAttribute implements InnerClassesAttribute { + + private static final Utf8Entry NAME = TemporaryConstantPool.INSTANCE.utf8Entry(Attributes.NAME_INNER_CLASSES); + private final List innerClasses; public UnboundInnerClassesAttribute(List innerClasses) { @@ -216,11 +275,19 @@ public abstract sealed class UnboundAttribute> public List classes() { return innerClasses; } + + @Override + public Utf8Entry attributeName() { + return NAME; + } } public static final class UnboundRecordAttribute extends UnboundAttribute implements RecordAttribute { + + private static final Utf8Entry NAME = TemporaryConstantPool.INSTANCE.utf8Entry(Attributes.NAME_RECORD); + private final List components; public UnboundRecordAttribute(List components) { @@ -232,11 +299,19 @@ public abstract sealed class UnboundAttribute> public List components() { return components; } + + @Override + public Utf8Entry attributeName() { + return NAME; + } } public static final class UnboundEnclosingMethodAttribute extends UnboundAttribute implements EnclosingMethodAttribute { + + private static final Utf8Entry NAME = TemporaryConstantPool.INSTANCE.utf8Entry(Attributes.NAME_ENCLOSING_METHOD); + private final ClassEntry classEntry; private final NameAndTypeEntry method; @@ -255,11 +330,19 @@ public abstract sealed class UnboundAttribute> public Optional enclosingMethod() { return Optional.ofNullable(method); } + + @Override + public Utf8Entry attributeName() { + return NAME; + } } public static final class UnboundMethodParametersAttribute extends UnboundAttribute implements MethodParametersAttribute { + + private static final Utf8Entry NAME = TemporaryConstantPool.INSTANCE.utf8Entry(Attributes.NAME_METHOD_PARAMETERS); + private final List parameters; public UnboundMethodParametersAttribute(List parameters) { @@ -271,11 +354,19 @@ public abstract sealed class UnboundAttribute> public List parameters() { return parameters; } + + @Override + public Utf8Entry attributeName() { + return NAME; + } } public static final class UnboundModuleTargetAttribute extends UnboundAttribute implements ModuleTargetAttribute { + + private static final Utf8Entry NAME = TemporaryConstantPool.INSTANCE.utf8Entry(Attributes.NAME_MODULE_TARGET); + final Utf8Entry moduleTarget; public UnboundModuleTargetAttribute(Utf8Entry moduleTarget) { @@ -287,11 +378,19 @@ public abstract sealed class UnboundAttribute> public Utf8Entry targetPlatform() { return moduleTarget; } + + @Override + public Utf8Entry attributeName() { + return NAME; + } } public static final class UnboundModuleMainClassAttribute extends UnboundAttribute implements ModuleMainClassAttribute { + + private static final Utf8Entry NAME = TemporaryConstantPool.INSTANCE.utf8Entry(Attributes.NAME_MODULE_MAIN_CLASS); + final ClassEntry mainClass; public UnboundModuleMainClassAttribute(ClassEntry mainClass) { @@ -303,11 +402,19 @@ public abstract sealed class UnboundAttribute> public ClassEntry mainClass() { return mainClass; } + + @Override + public Utf8Entry attributeName() { + return NAME; + } } public static final class UnboundModuleHashesAttribute extends UnboundAttribute implements ModuleHashesAttribute { + + private static final Utf8Entry NAME = TemporaryConstantPool.INSTANCE.utf8Entry(Attributes.NAME_MODULE_HASHES); + private final Utf8Entry algorithm; private final List hashes; @@ -326,11 +433,19 @@ public abstract sealed class UnboundAttribute> public List hashes() { return hashes; } + + @Override + public Utf8Entry attributeName() { + return NAME; + } } public static final class UnboundModulePackagesAttribute extends UnboundAttribute implements ModulePackagesAttribute { + + private static final Utf8Entry NAME = TemporaryConstantPool.INSTANCE.utf8Entry(Attributes.NAME_MODULE_PACKAGES); + private final Collection packages; public UnboundModulePackagesAttribute(Collection packages) { @@ -342,11 +457,19 @@ public abstract sealed class UnboundAttribute> public List packages() { return List.copyOf(packages); } + + @Override + public Utf8Entry attributeName() { + return NAME; + } } public static final class UnboundModuleResolutionAttribute extends UnboundAttribute implements ModuleResolutionAttribute { + + private static final Utf8Entry NAME = TemporaryConstantPool.INSTANCE.utf8Entry(Attributes.NAME_MODULE_RESOLUTION); + private final int resolutionFlags; public UnboundModuleResolutionAttribute(int flags) { @@ -358,11 +481,19 @@ public abstract sealed class UnboundAttribute> public int resolutionFlags() { return resolutionFlags; } + + @Override + public Utf8Entry attributeName() { + return NAME; + } } public static final class UnboundPermittedSubclassesAttribute extends UnboundAttribute implements PermittedSubclassesAttribute { + + private static final Utf8Entry NAME = TemporaryConstantPool.INSTANCE.utf8Entry(Attributes.NAME_PERMITTED_SUBCLASSES); + private final List permittedSubclasses; public UnboundPermittedSubclassesAttribute(List permittedSubclasses) { @@ -374,11 +505,19 @@ public abstract sealed class UnboundAttribute> public List permittedSubclasses() { return permittedSubclasses; } + + @Override + public Utf8Entry attributeName() { + return NAME; + } } public static final class UnboundNestMembersAttribute extends UnboundAttribute implements NestMembersAttribute { + + private static final Utf8Entry NAME = TemporaryConstantPool.INSTANCE.utf8Entry(Attributes.NAME_NEST_MEMBERS); + private final List memberEntries; public UnboundNestMembersAttribute(List memberEntries) { @@ -390,11 +529,19 @@ public abstract sealed class UnboundAttribute> public List nestMembers() { return memberEntries; } + + @Override + public Utf8Entry attributeName() { + return NAME; + } } public static final class UnboundNestHostAttribute extends UnboundAttribute implements NestHostAttribute { + + private static final Utf8Entry NAME = TemporaryConstantPool.INSTANCE.utf8Entry(Attributes.NAME_NEST_HOST); + private final ClassEntry hostEntry; public UnboundNestHostAttribute(ClassEntry hostEntry) { @@ -406,11 +553,19 @@ public abstract sealed class UnboundAttribute> public ClassEntry nestHost() { return hostEntry; } + + @Override + public Utf8Entry attributeName() { + return NAME; + } } public static final class UnboundCompilationIDAttribute extends UnboundAttribute implements CompilationIDAttribute { + + private static final Utf8Entry NAME = TemporaryConstantPool.INSTANCE.utf8Entry(Attributes.NAME_COMPILATION_ID); + private final Utf8Entry idEntry; public UnboundCompilationIDAttribute(Utf8Entry idEntry) { @@ -422,11 +577,19 @@ public abstract sealed class UnboundAttribute> public Utf8Entry compilationId() { return idEntry; } + + @Override + public Utf8Entry attributeName() { + return NAME; + } } public static final class UnboundSourceIDAttribute extends UnboundAttribute implements SourceIDAttribute { + + private static final Utf8Entry NAME = TemporaryConstantPool.INSTANCE.utf8Entry(Attributes.NAME_SOURCE_ID); + private final Utf8Entry idEntry; public UnboundSourceIDAttribute(Utf8Entry idEntry) { @@ -438,11 +601,19 @@ public abstract sealed class UnboundAttribute> public Utf8Entry sourceId() { return idEntry; } + + @Override + public Utf8Entry attributeName() { + return NAME; + } } public static final class UnboundSourceDebugExtensionAttribute extends UnboundAttribute implements SourceDebugExtensionAttribute { + + private static final Utf8Entry NAME = TemporaryConstantPool.INSTANCE.utf8Entry(Attributes.NAME_SOURCE_DEBUG_EXTENSION); + private final byte[] contents; public UnboundSourceDebugExtensionAttribute(byte[] contents) { @@ -454,11 +625,19 @@ public abstract sealed class UnboundAttribute> public byte[] contents() { return contents; } + + @Override + public Utf8Entry attributeName() { + return NAME; + } } public static final class UnboundCharacterRangeTableAttribute extends UnboundAttribute implements CharacterRangeTableAttribute { + + private static final Utf8Entry NAME = TemporaryConstantPool.INSTANCE.utf8Entry(Attributes.NAME_CHARACTER_RANGE_TABLE); + private final List ranges; public UnboundCharacterRangeTableAttribute(List ranges) { @@ -470,11 +649,19 @@ public abstract sealed class UnboundAttribute> public List characterRangeTable() { return ranges; } + + @Override + public Utf8Entry attributeName() { + return NAME; + } } public static final class UnboundLineNumberTableAttribute extends UnboundAttribute implements LineNumberTableAttribute { + + private static final Utf8Entry NAME = TemporaryConstantPool.INSTANCE.utf8Entry(Attributes.NAME_LINE_NUMBER_TABLE); + private final List lines; public UnboundLineNumberTableAttribute(List lines) { @@ -486,11 +673,19 @@ public abstract sealed class UnboundAttribute> public List lineNumbers() { return lines; } + + @Override + public Utf8Entry attributeName() { + return NAME; + } } public static final class UnboundLocalVariableTableAttribute extends UnboundAttribute implements LocalVariableTableAttribute { + + private static final Utf8Entry NAME = TemporaryConstantPool.INSTANCE.utf8Entry(Attributes.NAME_LOCAL_VARIABLE_TABLE); + private final List locals; public UnboundLocalVariableTableAttribute(List locals) { @@ -502,11 +697,19 @@ public abstract sealed class UnboundAttribute> public List localVariables() { return locals; } + + @Override + public Utf8Entry attributeName() { + return NAME; + } } public static final class UnboundLocalVariableTypeTableAttribute extends UnboundAttribute implements LocalVariableTypeTableAttribute { + + private static final Utf8Entry NAME = TemporaryConstantPool.INSTANCE.utf8Entry(Attributes.NAME_LOCAL_VARIABLE_TYPE_TABLE); + private final List locals; public UnboundLocalVariableTypeTableAttribute(List locals) { @@ -518,11 +721,19 @@ public abstract sealed class UnboundAttribute> public List localVariableTypes() { return locals; } + + @Override + public Utf8Entry attributeName() { + return NAME; + } } public static final class UnboundRuntimeVisibleAnnotationsAttribute extends UnboundAttribute implements RuntimeVisibleAnnotationsAttribute { + + private static final Utf8Entry NAME = TemporaryConstantPool.INSTANCE.utf8Entry(Attributes.NAME_RUNTIME_VISIBLE_ANNOTATIONS); + private final List elements; public UnboundRuntimeVisibleAnnotationsAttribute(List elements) { @@ -534,11 +745,19 @@ public abstract sealed class UnboundAttribute> public List annotations() { return elements; } + + @Override + public Utf8Entry attributeName() { + return NAME; + } } public static final class UnboundRuntimeInvisibleAnnotationsAttribute extends UnboundAttribute implements RuntimeInvisibleAnnotationsAttribute { + + private static final Utf8Entry NAME = TemporaryConstantPool.INSTANCE.utf8Entry(Attributes.NAME_RUNTIME_INVISIBLE_ANNOTATIONS); + private final List elements; public UnboundRuntimeInvisibleAnnotationsAttribute(List elements) { @@ -550,11 +769,19 @@ public abstract sealed class UnboundAttribute> public List annotations() { return elements; } + + @Override + public Utf8Entry attributeName() { + return NAME; + } } public static final class UnboundRuntimeVisibleParameterAnnotationsAttribute extends UnboundAttribute implements RuntimeVisibleParameterAnnotationsAttribute { + + private static final Utf8Entry NAME = TemporaryConstantPool.INSTANCE.utf8Entry(Attributes.NAME_RUNTIME_VISIBLE_PARAMETER_ANNOTATIONS); + private final List> elements; public UnboundRuntimeVisibleParameterAnnotationsAttribute(List> elements) { @@ -572,11 +799,19 @@ public abstract sealed class UnboundAttribute> public List> parameterAnnotations() { return elements; } + + @Override + public Utf8Entry attributeName() { + return NAME; + } } public static final class UnboundRuntimeInvisibleParameterAnnotationsAttribute extends UnboundAttribute implements RuntimeInvisibleParameterAnnotationsAttribute { + + private static final Utf8Entry NAME = TemporaryConstantPool.INSTANCE.utf8Entry(Attributes.NAME_RUNTIME_INVISIBLE_PARAMETER_ANNOTATIONS); + private final List> elements; public UnboundRuntimeInvisibleParameterAnnotationsAttribute(List> elements) { @@ -594,11 +829,19 @@ public abstract sealed class UnboundAttribute> public List> parameterAnnotations() { return elements; } + + @Override + public Utf8Entry attributeName() { + return NAME; + } } public static final class UnboundRuntimeVisibleTypeAnnotationsAttribute extends UnboundAttribute implements RuntimeVisibleTypeAnnotationsAttribute { + + private static final Utf8Entry NAME = TemporaryConstantPool.INSTANCE.utf8Entry(Attributes.NAME_RUNTIME_VISIBLE_TYPE_ANNOTATIONS); + private final List elements; public UnboundRuntimeVisibleTypeAnnotationsAttribute(List elements) { @@ -610,11 +853,19 @@ public abstract sealed class UnboundAttribute> public List annotations() { return elements; } + + @Override + public Utf8Entry attributeName() { + return NAME; + } } public static final class UnboundRuntimeInvisibleTypeAnnotationsAttribute extends UnboundAttribute implements RuntimeInvisibleTypeAnnotationsAttribute { + + private static final Utf8Entry NAME = TemporaryConstantPool.INSTANCE.utf8Entry(Attributes.NAME_RUNTIME_INVISIBLE_TYPE_ANNOTATIONS); + private final List elements; public UnboundRuntimeInvisibleTypeAnnotationsAttribute(List elements) { @@ -626,6 +877,11 @@ public abstract sealed class UnboundAttribute> public List annotations() { return elements; } + + @Override + public Utf8Entry attributeName() { + return NAME; + } } public record UnboundCharacterRangeInfo(int startPc, int endPc, @@ -749,6 +1005,9 @@ public abstract sealed class UnboundAttribute> implements TypeAnnotation.TypePathComponent {} public static final class UnboundModuleAttribute extends UnboundAttribute implements ModuleAttribute { + + private static final Utf8Entry NAME = TemporaryConstantPool.INSTANCE.utf8Entry(Attributes.NAME_MODULE); + private final ModuleEntry moduleName; private final int moduleFlags; private final Utf8Entry moduleVersion; @@ -817,6 +1076,11 @@ public abstract sealed class UnboundAttribute> public List provides() { return provides; } + + @Override + public Utf8Entry attributeName() { + return NAME; + } } public abstract static non-sealed class AdHocAttribute> @@ -841,6 +1105,9 @@ public abstract sealed class UnboundAttribute> public static final class EmptyBootstrapAttribute extends UnboundAttribute implements BootstrapMethodsAttribute { + + private static final Utf8Entry NAME = TemporaryConstantPool.INSTANCE.utf8Entry(Attributes.NAME_BOOTSTRAP_METHODS); + public EmptyBootstrapAttribute() { super(Attributes.bootstrapMethods()); } @@ -854,5 +1121,10 @@ public abstract sealed class UnboundAttribute> public List bootstrapMethods() { return List.of(); } + + @Override + public Utf8Entry attributeName() { + return NAME; + } } } diff --git a/src/java.base/share/classes/jdk/internal/classfile/impl/Util.java b/src/java.base/share/classes/jdk/internal/classfile/impl/Util.java index 1088724d8b4..fc6099f3e5b 100644 --- a/src/java.base/share/classes/jdk/internal/classfile/impl/Util.java +++ b/src/java.base/share/classes/jdk/internal/classfile/impl/Util.java @@ -281,6 +281,11 @@ public class Util { b.writeBytes(bytecode.array(), 0, bytecode.length()); b.writeU2U2(0, 0);//exception handlers & attributes } + + @Override + public Utf8Entry attributeName() { + return cp.utf8Entry(Attributes.NAME_CODE); + } })))); ClassPrinter.toYaml(clm.methods().get(0).code().get(), ClassPrinter.Verbosity.TRACE_ALL, dump); } catch (Error | Exception _) { diff --git a/src/java.base/share/classes/jdk/internal/classfile/impl/verifier/ParserVerifier.java b/src/java.base/share/classes/jdk/internal/classfile/impl/verifier/ParserVerifier.java index 521d74ae133..b7ddaace116 100644 --- a/src/java.base/share/classes/jdk/internal/classfile/impl/verifier/ParserVerifier.java +++ b/src/java.base/share/classes/jdk/internal/classfile/impl/verifier/ParserVerifier.java @@ -176,8 +176,8 @@ public record ParserVerifier(ClassModel classModel) { if (cfe instanceof AttributedElement ae) { var attrNames = new HashSet(); for (var a : ae.attributes()) { - if (!a.attributeMapper().allowMultiple() && !attrNames.add(a.attributeName())) { - errors.add(new VerifyError("Multiple %s attributes in %s".formatted(a.attributeName(), toString(ae)))); + if (!a.attributeMapper().allowMultiple() && !attrNames.add(a.attributeName().stringValue())) { + errors.add(new VerifyError("Multiple %s attributes in %s".formatted(a.attributeName().stringValue(), toString(ae)))); } verifyAttribute(ae, a, errors); } @@ -331,7 +331,7 @@ public record ParserVerifier(ClassModel classModel) { throw new AssertionError(a); }; if (size >= 0 && size != ((BoundAttribute)a).payloadLen()) { - errors.add(new VerifyError("Wrong %s attribute length in %s".formatted(a.attributeName(), toString(ae)))); + errors.add(new VerifyError("Wrong %s attribute length in %s".formatted(a.attributeName().stringValue(), toString(ae)))); } } diff --git a/src/jdk.jdeps/share/classes/com/sun/tools/javap/AttributeWriter.java b/src/jdk.jdeps/share/classes/com/sun/tools/javap/AttributeWriter.java index cccbaf14f53..2335d882ab1 100644 --- a/src/jdk.jdeps/share/classes/com/sun/tools/javap/AttributeWriter.java +++ b/src/jdk.jdeps/share/classes/com/sun/tools/javap/AttributeWriter.java @@ -84,7 +84,7 @@ public class AttributeWriter extends BasicWriter { int i = 0; int j = 0; print(" "); - print(attr.attributeName()); + print(attr.attributeName().stringValue()); print(": "); print("length = 0x" + toHex(data.length)); print(" (unknown attribute)"); diff --git a/test/jdk/jdk/classfile/BoundAttributeTest.java b/test/jdk/jdk/classfile/BoundAttributeTest.java index 6a164bec2f9..e8f12356128 100644 --- a/test/jdk/jdk/classfile/BoundAttributeTest.java +++ b/test/jdk/jdk/classfile/BoundAttributeTest.java @@ -41,6 +41,7 @@ import java.lang.classfile.CodeBuilder; import java.lang.classfile.attribute.MethodParameterInfo; import java.lang.classfile.attribute.MethodParametersAttribute; import java.lang.classfile.constantpool.ConstantPoolException; +import java.lang.classfile.constantpool.Utf8Entry; import java.lang.constant.ClassDesc; import java.lang.constant.ConstantDescs; import java.lang.constant.MethodTypeDesc; @@ -89,6 +90,11 @@ class BoundAttributeTest { b.writeIndex(oneClass); b.writeIndex(oneClassString); } + + @Override + public Utf8Entry attributeName() { + return cp.utf8Entry(Attributes.NAME_NEST_MEMBERS); + } }); }); diff --git a/test/jdk/jdk/classfile/CorpusTest.java b/test/jdk/jdk/classfile/CorpusTest.java index 631e2f8afaa..513005370e7 100644 --- a/test/jdk/jdk/classfile/CorpusTest.java +++ b/test/jdk/jdk/classfile/CorpusTest.java @@ -93,6 +93,11 @@ class CorpusTest { b.writeU2(curPc); b.writeU2(ln.line()); } + + @Override + public Utf8Entry attributeName() { + return cob.constantPool().utf8Entry(Attributes.NAME_LINE_NUMBER_TABLE); + } }); case LocalVariable lv -> dcob.writeAttribute(new UnboundAttribute.AdHocAttribute<>(Attributes.localVariableTable()) { @Override @@ -100,6 +105,11 @@ class CorpusTest { b.writeU2(1); Util.writeLocalVariable(b, lv); } + + @Override + public Utf8Entry attributeName() { + return cob.constantPool().utf8Entry(Attributes.NAME_LOCAL_VARIABLE_TABLE); + } }); case LocalVariableType lvt -> dcob.writeAttribute(new UnboundAttribute.AdHocAttribute<>(Attributes.localVariableTypeTable()) { @Override @@ -107,6 +117,11 @@ class CorpusTest { b.writeU2(1); Util.writeLocalVariable(b, lvt); } + + @Override + public Utf8Entry attributeName() { + return cob.constantPool().utf8Entry(Attributes.NAME_LOCAL_VARIABLE_TYPE_TABLE); + } }); default -> cob.with(coe); } diff --git a/test/jdk/jdk/classfile/LimitsTest.java b/test/jdk/jdk/classfile/LimitsTest.java index a1899ac1c84..6f3dc04c665 100644 --- a/test/jdk/jdk/classfile/LimitsTest.java +++ b/test/jdk/jdk/classfile/LimitsTest.java @@ -41,6 +41,7 @@ import java.lang.classfile.attribute.LocalVariableTableAttribute; import java.lang.classfile.constantpool.ConstantPoolBuilder; import java.lang.classfile.constantpool.ConstantPoolException; import java.lang.classfile.constantpool.IntegerEntry; +import java.lang.classfile.constantpool.Utf8Entry; import java.util.List; import jdk.internal.classfile.impl.BufWriterImpl; @@ -49,6 +50,7 @@ import jdk.internal.classfile.impl.DirectMethodBuilder; import jdk.internal.classfile.impl.LabelContext; import jdk.internal.classfile.impl.UnboundAttribute; import org.junit.jupiter.api.Test; + import static org.junit.jupiter.api.Assertions.*; class LimitsTest { @@ -145,7 +147,13 @@ class LimitsTest { b.writeInt(-2); //npairs to jump back and cause OOME if not checked b.writeU2(0);//exception handlers b.writeU2(0);//attributes - }})))).methods().get(0).code().get().elementList()); + } + + @Override + public Utf8Entry attributeName() { + return mb.constantPool().utf8Entry(Attributes.NAME_CODE); + } + })))).methods().get(0).code().get().elementList()); } @Test @@ -167,7 +175,13 @@ class LimitsTest { b.writeInt(-5); //high to jump back and cause OOME if not checked b.writeU2(0);//exception handlers b.writeU2(0);//attributes - }})))).methods().get(0).code().get().elementList()); + } + + @Override + public Utf8Entry attributeName() { + return mb.constantPool().utf8Entry(Attributes.NAME_CODE); + } + })))).methods().get(0).code().get().elementList()); assertThrows(IllegalArgumentException.class, () -> ClassFile.of().parse(ClassFile.of().build(ClassDesc.of("TableSwitchClass"), cb -> cb.withMethod( "tableSwitchMethod", MethodTypeDesc.of(ConstantDescs.CD_void), 0, mb -> @@ -189,7 +203,13 @@ class LimitsTest { b.writeInt(Integer.MAX_VALUE - 4); //high to jump back and cause infinite loop b.writeU2(0);//exception handlers b.writeU2(0);//attributes - }})))).methods().get(0).code().get().elementList()); + } + + @Override + public Utf8Entry attributeName() { + return mb.constantPool().utf8Entry(Attributes.NAME_CODE); + } + })))).methods().get(0).code().get().elementList()); } @Test diff --git a/test/jdk/jdk/classfile/LowJCovAttributeTest.java b/test/jdk/jdk/classfile/LowJCovAttributeTest.java index 858b9c90416..ed29a057357 100644 --- a/test/jdk/jdk/classfile/LowJCovAttributeTest.java +++ b/test/jdk/jdk/classfile/LowJCovAttributeTest.java @@ -76,7 +76,7 @@ class LowJCovAttributeTest { private void testRead0() { int[] mask = new int[1]; for (Attribute attr : classLow.attributes()) { - switch (attr.attributeName()) { + switch (attr.attributeName().stringValue()) { case Attributes.NAME_COMPILATION_ID: { CompilationIDAttribute cid = (CompilationIDAttribute) attr; Utf8Entry v = cid.compilationId(); diff --git a/test/jdk/jdk/classfile/LowModuleTest.java b/test/jdk/jdk/classfile/LowModuleTest.java index e78eff74d1d..b017fe84756 100644 --- a/test/jdk/jdk/classfile/LowModuleTest.java +++ b/test/jdk/jdk/classfile/LowModuleTest.java @@ -77,7 +77,7 @@ class LowModuleTest { private void testRead0(ClassModel classLow) { for (Attribute attr : classLow.attributes()) { - switch (attr.attributeName()) { + switch (attr.attributeName().stringValue()) { case Attributes.NAME_SOURCE_FILE: { SourceFileAttribute sfa = (SourceFileAttribute) attr; Utf8Entry sf = sfa.sourceFile(); diff --git a/test/jdk/jdk/classfile/VerifierSelfTest.java b/test/jdk/jdk/classfile/VerifierSelfTest.java index b6a2f08c9ec..1f9f199a33b 100644 --- a/test/jdk/jdk/classfile/VerifierSelfTest.java +++ b/test/jdk/jdk/classfile/VerifierSelfTest.java @@ -31,7 +31,9 @@ import java.io.IOException; import java.lang.classfile.constantpool.PoolEntry; import java.lang.constant.ClassDesc; + import static java.lang.constant.ConstantDescs.*; + import java.lang.invoke.MethodHandleInfo; import java.net.URI; import java.nio.file.FileSystem; @@ -47,12 +49,14 @@ import java.util.stream.Stream; import java.lang.classfile.*; import java.lang.classfile.attribute.*; import java.lang.classfile.components.ClassPrinter; +import java.lang.classfile.constantpool.Utf8Entry; import java.lang.constant.ModuleDesc; import jdk.internal.classfile.impl.BufWriterImpl; import jdk.internal.classfile.impl.DirectClassBuilder; import jdk.internal.classfile.impl.UnboundAttribute; import org.junit.jupiter.api.Test; + import static org.junit.jupiter.api.Assertions.*; class VerifierSelfTest { @@ -109,6 +113,11 @@ class VerifierSelfTest { public void writeBody(BufWriterImpl b) { b.writeU2(0); } + + @Override + public Utf8Entry attributeName() { + return cb.constantPool().utf8Entry(Attributes.NAME_LOCAL_VARIABLE_TABLE); + } })); assertTrue(cc.verify(bytes).stream().anyMatch(e -> e.getMessage().contains("Invalid LocalVariableTable attribute location"))); } @@ -366,7 +375,7 @@ class VerifierSelfTest { super(new AttributeMapper(){ @Override public String name() { - return a.attributeName(); + return a.attributeName().stringValue(); } @Override diff --git a/test/jdk/jdk/classfile/helpers/ClassRecord.java b/test/jdk/jdk/classfile/helpers/ClassRecord.java index e7a239015f6..c663721ec9f 100644 --- a/test/jdk/jdk/classfile/helpers/ClassRecord.java +++ b/test/jdk/jdk/classfile/helpers/ClassRecord.java @@ -234,7 +234,7 @@ public record ClassRecord( public static AttributesRecord ofStreamingElements(Supplier> elements, ConstantPool cp, CompatibilityFilter... cf) { Map> attrs = elements.get().filter(e -> e instanceof Attribute) .map(e -> (Attribute) e) - .collect(toMap(Attribute::attributeName, e -> e)); + .collect(toMap(a -> a.attributeName().stringValue(), e -> e)); return new AttributesRecord( mapAttr(attrs, annotationDefault(), a -> ElementValueRecord.ofElementValue(a.defaultValue())), cp == null ? null : IntStream.range(0, cp.bootstrapMethodCount()).mapToObj(i -> BootstrapMethodRecord.ofBootstrapMethodEntry(cp.bootstrapMethodEntry(i))).collect(toSetOrNull()), diff --git a/test/jdk/jdk/classfile/helpers/RebuildingTransformation.java b/test/jdk/jdk/classfile/helpers/RebuildingTransformation.java index c1d9781b6ce..b0e1d6c312d 100644 --- a/test/jdk/jdk/classfile/helpers/RebuildingTransformation.java +++ b/test/jdk/jdk/classfile/helpers/RebuildingTransformation.java @@ -59,8 +59,8 @@ class RebuildingTransformation { case RuntimeVisibleTypeAnnotationsAttribute a -> fb.with(RuntimeVisibleTypeAnnotationsAttribute.of(transformTypeAnnotations(a.annotations(), null, null))); case SignatureAttribute a -> fb.with(SignatureAttribute.of(Signature.parseFrom(a.asTypeSignature().signatureString()))); case SyntheticAttribute a -> fb.with(SyntheticAttribute.of()); - case CustomAttribute a -> throw new AssertionError("Unexpected custom attribute: " + a.attributeName()); - case UnknownAttribute a -> throw new AssertionError("Unexpected unknown attribute: " + a.attributeName()); + case CustomAttribute a -> throw new AssertionError("Unexpected custom attribute: " + a.attributeName().stringValue()); + case UnknownAttribute a -> throw new AssertionError("Unexpected unknown attribute: " + a.attributeName().stringValue()); } } }); @@ -91,8 +91,8 @@ class RebuildingTransformation { case RuntimeVisibleTypeAnnotationsAttribute a -> mb.with(RuntimeVisibleTypeAnnotationsAttribute.of(transformTypeAnnotations(a.annotations(), null, null))); case SignatureAttribute a -> mb.with(SignatureAttribute.of(MethodSignature.parseFrom(a.asMethodSignature().signatureString()))); case SyntheticAttribute a -> mb.with(SyntheticAttribute.of()); - case CustomAttribute a -> throw new AssertionError("Unexpected custom attribute: " + a.attributeName()); - case UnknownAttribute a -> throw new AssertionError("Unexpected unknown attribute: " + a.attributeName()); + case CustomAttribute a -> throw new AssertionError("Unexpected custom attribute: " + a.attributeName().stringValue()); + case UnknownAttribute a -> throw new AssertionError("Unexpected unknown attribute: " + a.attributeName().stringValue()); } } }); @@ -131,7 +131,7 @@ class RebuildingTransformation { case RuntimeVisibleAnnotationsAttribute rvaa -> rcac.accept(RuntimeVisibleAnnotationsAttribute.of(transformAnnotations(rvaa.annotations()))); case RuntimeVisibleTypeAnnotationsAttribute rvtaa -> rcac.accept(RuntimeVisibleTypeAnnotationsAttribute.of(transformTypeAnnotations(rvtaa.annotations(), null, null))); case SignatureAttribute sa -> rcac.accept(SignatureAttribute.of(Signature.parseFrom(sa.asTypeSignature().signatureString()))); - default -> throw new AssertionError("Unexpected record component attribute: " + rca.attributeName()); + default -> throw new AssertionError("Unexpected record component attribute: " + rca.attributeName().stringValue()); }}).toArray(Attribute[]::new))).toArray(RecordComponentInfo[]::new))); case RuntimeInvisibleAnnotationsAttribute a -> clb.with(RuntimeInvisibleAnnotationsAttribute.of(transformAnnotations(a.annotations()))); case RuntimeInvisibleTypeAnnotationsAttribute a -> clb.with(RuntimeInvisibleTypeAnnotationsAttribute.of(transformTypeAnnotations(a.annotations(), null, null))); @@ -142,8 +142,8 @@ class RebuildingTransformation { case SourceFileAttribute a -> clb.with(SourceFileAttribute.of(a.sourceFile().stringValue())); case SourceIDAttribute a -> clb.with(SourceIDAttribute.of(a.sourceId().stringValue())); case SyntheticAttribute a -> clb.with(SyntheticAttribute.of()); - case CustomAttribute a -> throw new AssertionError("Unexpected custom attribute: " + a.attributeName()); - case UnknownAttribute a -> throw new AssertionError("Unexpected unknown attribute: " + a.attributeName()); + case CustomAttribute a -> throw new AssertionError("Unexpected custom attribute: " + a.attributeName().stringValue()); + case UnknownAttribute a -> throw new AssertionError("Unexpected unknown attribute: " + a.attributeName().stringValue()); } } }); @@ -595,7 +595,7 @@ class RebuildingTransformation { transformFrameTypeInfos(fr.locals(), cob, labels), transformFrameTypeInfos(fr.stack(), cob, labels))).toList())); case CustomAttribute a -> - throw new AssertionError("Unexpected custom attribute: " + a.attributeName()); + throw new AssertionError("Unexpected custom attribute: " + a.attributeName().stringValue()); } } } diff --git a/test/langtools/tools/javac/classfiles/attributes/AnnotationDefault/AnnotationDefaultTest.java b/test/langtools/tools/javac/classfiles/attributes/AnnotationDefault/AnnotationDefaultTest.java index d9a3320ecc2..2911e58820f 100644 --- a/test/langtools/tools/javac/classfiles/attributes/AnnotationDefault/AnnotationDefaultTest.java +++ b/test/langtools/tools/javac/classfiles/attributes/AnnotationDefault/AnnotationDefaultTest.java @@ -88,7 +88,7 @@ public class AnnotationDefaultTest extends TestResult { checkEquals(countNumberOfAttributes(method.attributes()), 1L, "Number of AnnotationDefault attribute"); - checkEquals(attr.attributeName(), + checkEquals(attr.attributeName().stringValue(), "AnnotationDefault", "attribute_name_index"); ExpectedValues expectedValue = expectedValues.get(methodName); diff --git a/test/langtools/tools/javac/classfiles/attributes/EnclosingMethod/EnclosingMethodTest.java b/test/langtools/tools/javac/classfiles/attributes/EnclosingMethod/EnclosingMethodTest.java index f15771840f5..924916f5cbd 100644 --- a/test/langtools/tools/javac/classfiles/attributes/EnclosingMethod/EnclosingMethodTest.java +++ b/test/langtools/tools/javac/classfiles/attributes/EnclosingMethod/EnclosingMethodTest.java @@ -169,7 +169,7 @@ public class EnclosingMethodTest extends TestResult { // stop checking, attr is null. test case failed return; } - checkEquals(attr.attributeName(), + checkEquals(attr.attributeName().stringValue(), "EnclosingMethod", "attribute_name_index of EnclosingMethod attribute in the class : " + className); checkEquals(((BoundAttribute)attr).payloadLen(), 4, diff --git a/test/langtools/tools/javac/classfiles/attributes/LineNumberTable/LineNumberTestBase.java b/test/langtools/tools/javac/classfiles/attributes/LineNumberTable/LineNumberTestBase.java index be4a5aaea91..531d5e617d0 100644 --- a/test/langtools/tools/javac/classfiles/attributes/LineNumberTable/LineNumberTestBase.java +++ b/test/langtools/tools/javac/classfiles/attributes/LineNumberTable/LineNumberTestBase.java @@ -138,7 +138,7 @@ public class LineNumberTestBase extends TestBase { private > int countAttributes(AttributeMapper attr, AttributedElement attributedElement) { int i = 0; for (Attribute attribute : attributedElement.attributes()) { - if (attribute.attributeName().equals(attr.name())) { + if (attribute.attributeName().equalsString(attr.name())) { i++; } } diff --git a/test/langtools/tools/javac/classfiles/attributes/Signature/Driver.java b/test/langtools/tools/javac/classfiles/attributes/Signature/Driver.java index 72f7d2a6b9b..7b75ffa5f9c 100644 --- a/test/langtools/tools/javac/classfiles/attributes/Signature/Driver.java +++ b/test/langtools/tools/javac/classfiles/attributes/Signature/Driver.java @@ -219,7 +219,7 @@ public class Driver extends TestResult { SignatureAttribute attribute = sup.get(); if (expectedSignature != null && checkNotNull(attribute, memberName + " must have attribute")) { - checkEquals(attribute.attributeName(), + checkEquals(attribute.attributeName().stringValue(), "Signature", "Attribute's name : " + memberName); checkEquals(((BoundAttribute)attribute).payloadLen(), 2, "Attribute's length : " + memberName); checkEquals(attribute.signature().stringValue(), diff --git a/test/langtools/tools/javac/classfiles/attributes/SourceFile/SourceFileTestBase.java b/test/langtools/tools/javac/classfiles/attributes/SourceFile/SourceFileTestBase.java index 52d53f9dce4..0d81fc2c282 100644 --- a/test/langtools/tools/javac/classfiles/attributes/SourceFile/SourceFileTestBase.java +++ b/test/langtools/tools/javac/classfiles/attributes/SourceFile/SourceFileTestBase.java @@ -108,7 +108,7 @@ public class SourceFileTestBase extends TestBase { SourceFileAttribute attribute = sourceFileAttributes.get(0); - assertEquals(attribute.attributeName(), Attributes.sourceFile().name(), "Incorrect attribute name"); + assertEquals(attribute.attributeName().stringValue(), Attributes.sourceFile().name(), "Incorrect attribute name"); assertEquals(attribute.sourceFile().stringValue(), fileName, "Incorrect source file name"); assertEquals(((BoundAttribute)attribute).payloadLen(), 2, "Incorrect attribute length"); diff --git a/test/langtools/tools/javac/classfiles/attributes/deprecated/DeprecatedTest.java b/test/langtools/tools/javac/classfiles/attributes/deprecated/DeprecatedTest.java index 425760ea137..6467f3d8027 100644 --- a/test/langtools/tools/javac/classfiles/attributes/deprecated/DeprecatedTest.java +++ b/test/langtools/tools/javac/classfiles/attributes/deprecated/DeprecatedTest.java @@ -302,7 +302,7 @@ public class DeprecatedTest extends TestResult { if (checkNotNull(attr, name + " must have deprecated attribute")) { checkEquals(0, ((BoundAttribute)attr).payloadLen(), "attribute_length should equal to 0"); - checkEquals("Deprecated", attr.attributeName(), + checkEquals("Deprecated", attr.attributeName().stringValue(), name + " attribute_name_index"); } } diff --git a/test/langtools/tools/javac/classfiles/attributes/innerclasses/InnerClassesTestBase.java b/test/langtools/tools/javac/classfiles/attributes/innerclasses/InnerClassesTestBase.java index 26972de3544..aa46d8a9b9d 100644 --- a/test/langtools/tools/javac/classfiles/attributes/innerclasses/InnerClassesTestBase.java +++ b/test/langtools/tools/javac/classfiles/attributes/innerclasses/InnerClassesTestBase.java @@ -206,7 +206,7 @@ public abstract class InnerClassesTestBase extends TestResult { if (!checkNotNull(innerClasses, "InnerClasses attribute should not be null")) { return; } - checkEquals(innerClasses.attributeName(), "InnerClasses", + checkEquals(innerClasses.attributeName().stringValue(), "InnerClasses", "innerClasses.attribute_name_index"); // Inner Classes attribute consists of length (2 bytes) // and 8 bytes for each inner class's entry. diff --git a/test/langtools/tools/javac/sealed/CheckSubtypesOfSealedTest.java b/test/langtools/tools/javac/sealed/CheckSubtypesOfSealedTest.java index 0366d4982ca..0f9634423ec 100644 --- a/test/langtools/tools/javac/sealed/CheckSubtypesOfSealedTest.java +++ b/test/langtools/tools/javac/sealed/CheckSubtypesOfSealedTest.java @@ -76,7 +76,7 @@ public class CheckSubtypesOfSealedTest extends TestBase { void check(ClassModel classFile) throws Exception { boolean found = false; for (Attribute attr: classFile.attributes()) { - if (attr.attributeName().equals("PermittedSubclasses")) { + if (attr.attributeName().equalsString("PermittedSubclasses")) { PermittedSubclassesAttribute permittedSubclasses = (PermittedSubclassesAttribute)attr; found = true; if (permittedSubclasses.permittedSubclasses().isEmpty()) { @@ -99,7 +99,7 @@ public class CheckSubtypesOfSealedTest extends TestBase { NOT_SEALED { void check(ClassModel classFile) throws Exception { for (Attribute attr: classFile.attributes()) { - if (attr.attributeName().equals("PermittedSubclasses")) { + if (attr.attributeName().equalsString("PermittedSubclasses")) { throw new AssertionError(classFile.thisClass().name() + " should not be sealed"); } } diff --git a/test/langtools/tools/javap/T6716452.java b/test/langtools/tools/javap/T6716452.java index 63ccead52e7..20c382918c3 100644 --- a/test/langtools/tools/javap/T6716452.java +++ b/test/langtools/tools/javap/T6716452.java @@ -70,7 +70,7 @@ public class T6716452 { if (!c.isAssignableFrom(mm.attributes().get(index).getClass())) { error(mm + ": unexpected attribute found," + " expected " + c.getName() - + " found " + mm.attributes().get(index).attributeName()); + + " found " + mm.attributes().get(index).attributeName().stringValue()); } } else { error(mm + ": expected attribute " + attr.name() + " not found");