Skip to content

Commit a461369

Browse files
committedAug 23, 2024
8338700: AttributeMapper type parameter should be bounded by Attribute
Reviewed-by: asotona
1 parent 916f1aa commit a461369

File tree

5 files changed

+6
-6
lines changed

5 files changed

+6
-6
lines changed
 

‎src/java.base/share/classes/java/lang/classfile/AttributeMapper.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2022, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -40,7 +40,7 @@
4040
* @since 22
4141
*/
4242
@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API)
43-
public interface AttributeMapper<A> {
43+
public interface AttributeMapper<A extends Attribute<A>> {
4444

4545
/**
4646
* Attribute stability indicator

‎src/java.base/share/classes/java/lang/classfile/package-info.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@
147147
* ClassReader, int)} method for mapping from the classfile format
148148
* to an attribute instance, and the
149149
* {@link java.lang.classfile.AttributeMapper#writeAttribute(java.lang.classfile.BufWriter,
150-
* java.lang.Object)} method for mapping back to the classfile format. It also
150+
* java.lang.classfile.Attribute)} method for mapping back to the classfile format. It also
151151
* contains metadata including the attribute name, the set of classfile entities
152152
* where the attribute is applicable, and whether multiple attributes of the
153153
* same kind are allowed on a single entity.

‎src/java.base/share/classes/jdk/internal/classfile/impl/AttributeHolder.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public void writeTo(BufWriterImpl buf) {
5454
}
5555

5656
@SuppressWarnings("unchecked")
57-
<A> A get(AttributeMapper<A> am) {
57+
<A extends Attribute<A>> A get(AttributeMapper<A> am) {
5858
for (Attribute<?> a : attributes)
5959
if (a.attributeMapper() == am)
6060
return (A)a;

‎src/java.base/share/classes/jdk/internal/classfile/impl/BoundAttribute.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ public static List<Attribute<?>> readAttributes(AttributedElement enclosing, Cla
148148
mapper = customAttributes.apply(name);
149149
}
150150
if (mapper != null) {
151-
filled.add((Attribute<?>) Objects.requireNonNull(mapper.readAttribute(enclosing, reader, p)));
151+
filled.add(Objects.requireNonNull(mapper.readAttribute(enclosing, reader, p)));
152152
} else {
153153
AttributeMapper<UnknownAttribute> fakeMapper = new AttributeMapper<>() {
154154
@Override

‎src/java.base/share/classes/jdk/internal/classfile/impl/Util.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ public static MethodTypeDesc methodTypeSymbol(NameAndTypeEntry nat) {
224224
}
225225

226226
@SuppressWarnings("unchecked")
227-
private static <T> void writeAttribute(BufWriterImpl writer, Attribute<?> attr) {
227+
private static <T extends Attribute<T>> void writeAttribute(BufWriterImpl writer, Attribute<?> attr) {
228228
if (attr instanceof CustomAttribute<?> ca) {
229229
var mapper = (AttributeMapper<T>) ca.attributeMapper();
230230
mapper.writeAttribute(writer, (T) ca);

0 commit comments

Comments
 (0)
Please sign in to comment.