This is an automated email from the ASF dual-hosted git repository.
garydgregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-bcel.git
The following commit(s) were added to refs/heads/master by this push:
new c64231e8 Use correct attribute tag in NestHost and ModuleMainClass
(#507)
c64231e8 is described below
commit c64231e86392f288fb0524b7fd644bf4f020ab7b
Author: Dexter.k <[email protected]>
AuthorDate: Sun Jun 21 19:38:09 2026 +0000
Use correct attribute tag in NestHost and ModuleMainClass (#507)
---
.../org/apache/bcel/classfile/ModuleMainClass.java | 2 +-
.../java/org/apache/bcel/classfile/NestHost.java | 2 +-
.../apache/bcel/classfile/AttributeTagTest.java | 46 ++++++++++++++++++++++
3 files changed, 48 insertions(+), 2 deletions(-)
diff --git a/src/main/java/org/apache/bcel/classfile/ModuleMainClass.java
b/src/main/java/org/apache/bcel/classfile/ModuleMainClass.java
index 91177a69..b04a7a29 100644
--- a/src/main/java/org/apache/bcel/classfile/ModuleMainClass.java
+++ b/src/main/java/org/apache/bcel/classfile/ModuleMainClass.java
@@ -59,7 +59,7 @@ public final class ModuleMainClass extends Attribute {
* @param constantPool Array of constants.
*/
public ModuleMainClass(final int nameIndex, final int length, final int
mainClassIndex, final ConstantPool constantPool) {
- super(Const.ATTR_NEST_MEMBERS, nameIndex, length, constantPool);
+ super(Const.ATTR_MODULE_MAIN_CLASS, nameIndex, length, constantPool);
this.mainClassIndex = Args.requireU2(mainClassIndex, "mainClassIndex");
}
diff --git a/src/main/java/org/apache/bcel/classfile/NestHost.java
b/src/main/java/org/apache/bcel/classfile/NestHost.java
index 9c2ffb71..a242625c 100644
--- a/src/main/java/org/apache/bcel/classfile/NestHost.java
+++ b/src/main/java/org/apache/bcel/classfile/NestHost.java
@@ -59,7 +59,7 @@ public final class NestHost extends Attribute {
* @param constantPool Array of constants.
*/
public NestHost(final int nameIndex, final int length, final int
hostClassIndex, final ConstantPool constantPool) {
- super(Const.ATTR_NEST_MEMBERS, nameIndex, length, constantPool);
+ super(Const.ATTR_NEST_HOST, nameIndex, length, constantPool);
this.hostClassIndex = Args.requireU2(hostClassIndex, "hostClassIndex");
}
diff --git a/src/test/java/org/apache/bcel/classfile/AttributeTagTest.java
b/src/test/java/org/apache/bcel/classfile/AttributeTagTest.java
new file mode 100644
index 00000000..17cb75be
--- /dev/null
+++ b/src/test/java/org/apache/bcel/classfile/AttributeTagTest.java
@@ -0,0 +1,46 @@
+/*
+ * 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 static org.junit.jupiter.api.Assertions.assertEquals;
+
+import org.apache.bcel.Const;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Tests that attribute objects report their own tag via {@link
Attribute#getTag()}, which {@code getAttribute(byte)}
+ * relies on for lookups.
+ */
+class AttributeTagTest {
+
+ @Test
+ void moduleMainClassReportsModuleMainClassTag() {
+ final ModuleMainClass attribute = new ModuleMainClass(0, 2, 0, new
ConstantPool());
+ assertEquals(Const.ATTR_MODULE_MAIN_CLASS, attribute.getTag());
+ assertEquals("ModuleMainClass",
Const.getAttributeName(attribute.getTag()));
+ }
+
+ @Test
+ void nestHostReportsNestHostTag() {
+ final NestHost attribute = new NestHost(0, 2, 0, new ConstantPool());
+ assertEquals(Const.ATTR_NEST_HOST, attribute.getTag());
+ assertEquals("NestHost", Const.getAttributeName(attribute.getTag()));
+ }
+}