Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/changes/changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ The <action> type attribute can be add,update,fix,remove.
<action type="fix" dev="ggregory" due-to="Gary Gregory">Update ECJ versions and generate the SWAP fixture with BCEL (#537).</action>
<!-- ADD -->
<action type="add" dev="ggregory" due-to="Gary Gregory">Add and use ClassFormatException.ClassFormatException(String, Object...).</action>
<action type="add" dev="ggregory" due-to="Nicolas Baumann">Add support for the RuntimeVisibleTypeAnnotations and RuntimeInvisibleTypeAnnotations attributes.</action>
<!-- UPDATE -->
<action type="update" dev="ggregory" due-to="Gary Gregory">Bump org.apache.commons:commons-parent from 104 to 106.</action>
<action type="update" dev="ggregory" due-to="Gary Gregory">Bump org.apache.commons:commons-lang3 from 3.20.0 to 3.21.0 #531.</action>
Expand Down
18 changes: 16 additions & 2 deletions src/main/java/org/apache/bcel/Const.java
Original file line number Diff line number Diff line change
Expand Up @@ -3207,14 +3207,28 @@ public final class Const {
*/
public static final byte ATTR_PERMITTED_SUBCLASSES = 28;

/**
* Attribute constant for RuntimeVisibleTypeAnnotations.
*
* @since 6.14.0
*/
public static final byte ATTR_RUNTIME_VISIBLE_TYPE_ANNOTATIONS = 29;

/**
* Attribute constant for RuntimeInvisibleTypeAnnotations.
*
* @since 6.14.0
*/
public static final byte ATTR_RUNTIME_INVISIBLE_TYPE_ANNOTATIONS = 30;

/** Count of known attributes. */
public static final short KNOWN_ATTRIBUTES = 29; // count of attributes
public static final short KNOWN_ATTRIBUTES = 31; // count of attributes

private static final String[] ATTRIBUTE_NAMES = { "SourceFile", "ConstantValue", "Code", "Exceptions", "LineNumberTable", "LocalVariableTable",
"InnerClasses", "Synthetic", "Deprecated", "PMGClass", "Signature", "StackMap", "RuntimeVisibleAnnotations", "RuntimeInvisibleAnnotations",
"RuntimeVisibleParameterAnnotations", "RuntimeInvisibleParameterAnnotations", "AnnotationDefault", "LocalVariableTypeTable", "EnclosingMethod",
"StackMapTable", "BootstrapMethods", "MethodParameters", "Module", "ModulePackages", "ModuleMainClass", "NestHost", "NestMembers", "Record",
"PermittedSubclasses" };
"PermittedSubclasses", "RuntimeVisibleTypeAnnotations", "RuntimeInvisibleTypeAnnotations" };

/**
* Constants used in the StackMap attribute.
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/org/apache/bcel/classfile/Attribute.java
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,10 @@ private static Attribute readAttribute0(final DataInput dataInput, final Constan
return new Record(nameIndex, length, dataInput, constantPool);
case Const.ATTR_PERMITTED_SUBCLASSES:
return new PermittedSubclasses(nameIndex, length, dataInput, constantPool);
case Const.ATTR_RUNTIME_VISIBLE_TYPE_ANNOTATIONS:
return new RuntimeVisibleTypeAnnotations(nameIndex, length, dataInput, constantPool);
case Const.ATTR_RUNTIME_INVISIBLE_TYPE_ANNOTATIONS:
return new RuntimeInvisibleTypeAnnotations(nameIndex, length, dataInput, constantPool);
default:
// Never reached
throw new IllegalStateException("Unrecognized attribute type tag parsed: " + tag);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,15 @@ public void visitRecordComponent(final RecordComponentInfo recordComponentInfo)
stack.pop();
}

/** @since 6.14.0 */
@Override
public void visitTypeAnnotations(final TypeAnnotations obj) {
stack.push(obj);
obj.accept(visitor);
accept(Stream.of(obj.getTypeAnnotationEntries()).map(TypeAnnotationEntry::getAnnotationEntry).toArray(AnnotationEntry[]::new));
stack.pop();
}

@Override
public void visitSignature(final Signature attribute) {
stack.push(attribute);
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/org/apache/bcel/classfile/EmptyVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,11 @@ public void visitParameterAnnotationEntry(final ParameterAnnotationEntry paramet
public void visitPermittedSubclasses(final PermittedSubclasses obj) {
}

/** @since 6.14.0 */
@Override
public void visitTypeAnnotations(final TypeAnnotations obj) {
}

@Override
public void visitSignature(final Signature obj) {
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.bcel.classfile;

import java.io.DataInput;
import java.io.DataOutputStream;
import java.io.IOException;

import org.apache.bcel.Const;

/**
* The type annotations of a class, field, method, record component or {@link Code} attribute, recorded in the class file but not visible at runtime.
*
* @since 6.14.0
*/
public class RuntimeInvisibleTypeAnnotations extends TypeAnnotations {

/**
* Constructs a new instance.
*
* @param nameIndex Index pointing to the name of the attribute.
* @param length Content length in bytes.
* @param input Input stream.
* @param constantPool Array of constants.
* @throws IOException Thrown when an I/O exception of some sort has occurred.
*/
public RuntimeInvisibleTypeAnnotations(final int nameIndex, final int length, final DataInput input, final ConstantPool constantPool) throws IOException {
super(Const.ATTR_RUNTIME_INVISIBLE_TYPE_ANNOTATIONS, nameIndex, length, input, constantPool, false);
}

/**
* Creates a deep copy of this attribute, whose type annotations are independent of this one's and refer to the given constant pool.
*
* @param constantPool The constant pool of the copy.
* @return deep copy of this attribute.
*/
@Override
public Attribute copy(final ConstantPool constantPool) {
final RuntimeInvisibleTypeAnnotations c = (RuntimeInvisibleTypeAnnotations) clone();
c.setConstantPool(constantPool);
c.setTypeAnnotationTable(copyTypeAnnotations(constantPool));
return c;
}

@Override
public final void dump(final DataOutputStream dos) throws IOException {
super.dump(dos);
writeTypeAnnotations(dos);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.bcel.classfile;

import java.io.DataInput;
import java.io.DataOutputStream;
import java.io.IOException;

import org.apache.bcel.Const;

/**
* The type annotations of a class, field, method, record component or {@link Code} attribute, provided to the JVM and visible at runtime.
*
* @since 6.14.0
*/
public class RuntimeVisibleTypeAnnotations extends TypeAnnotations {

/**
* Constructs a new instance.
*
* @param nameIndex Index pointing to the name of the attribute.
* @param length Content length in bytes.
* @param input Input stream.
* @param constantPool Array of constants.
* @throws IOException Thrown when an I/O exception of some sort has occurred.
*/
public RuntimeVisibleTypeAnnotations(final int nameIndex, final int length, final DataInput input, final ConstantPool constantPool) throws IOException {
super(Const.ATTR_RUNTIME_VISIBLE_TYPE_ANNOTATIONS, nameIndex, length, input, constantPool, true);
}

/**
* Creates a deep copy of this attribute, whose type annotations are independent of this one's and refer to the given constant pool.
*
* @param constantPool The constant pool of the copy.
* @return deep copy of this attribute.
*/
@Override
public Attribute copy(final ConstantPool constantPool) {
final RuntimeVisibleTypeAnnotations c = (RuntimeVisibleTypeAnnotations) clone();
c.setConstantPool(constantPool);
c.setTypeAnnotationTable(copyTypeAnnotations(constantPool));
return c;
}

@Override
public final void dump(final DataOutputStream dos) throws IOException {
super.dump(dos);
writeTypeAnnotations(dos);
}
}
Loading
Loading