From 7b9ed9fa13820405043646a43ad2d36d8bacfdb9 Mon Sep 17 00:00:00 2001 From: nbauma109 Date: Sun, 1 Feb 2026 15:15:14 +0100 Subject: [PATCH 1/6] Add support for permitted subclasses --- src/main/java/org/apache/bcel/Const.java | 10 +- .../org/apache/bcel/classfile/Attribute.java | 2 + .../bcel/classfile/DescendingVisitor.java | 8 + .../apache/bcel/classfile/EmptyVisitor.java | 5 + .../bcel/classfile/PermittedSubclasses.java | 163 ++++++++++++++++++ .../org/apache/bcel/classfile/Visitor.java | 10 ++ .../statics/StringRepresentation.java | 9 + .../classfile/PermittedSubclassesTest.java | 72 ++++++++ src/test/resources/sealed/SealedDemo.java | 43 +++++ .../sealed/sealed-demo-jdk21.0.8.jar | Bin 0 -> 2788 bytes 10 files changed, 320 insertions(+), 2 deletions(-) create mode 100644 src/main/java/org/apache/bcel/classfile/PermittedSubclasses.java create mode 100644 src/test/java/org/apache/bcel/classfile/PermittedSubclassesTest.java create mode 100644 src/test/resources/sealed/SealedDemo.java create mode 100644 src/test/resources/sealed/sealed-demo-jdk21.0.8.jar diff --git a/src/main/java/org/apache/bcel/Const.java b/src/main/java/org/apache/bcel/Const.java index 24445b2e39..8d188c2271 100644 --- a/src/main/java/org/apache/bcel/Const.java +++ b/src/main/java/org/apache/bcel/Const.java @@ -3168,13 +3168,19 @@ public final class Const { /** Attribute constant for Record. */ public static final byte ATTR_RECORD = 27; + /** Attribute constant for PermittedSubclasses. + * @since 6.13.0 + */ + public static final byte ATTR_PERMITTED_SUBCLASSES = 28; + /** Count of known attributes. */ - public static final short KNOWN_ATTRIBUTES = 28; // count of attributes + public static final short KNOWN_ATTRIBUTES = 29; // 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" }; + "StackMapTable", "BootstrapMethods", "MethodParameters", "Module", "ModulePackages", "ModuleMainClass", "NestHost", "NestMembers", "Record", + "PermittedSubclasses" }; /** * Constants used in the StackMap attribute. diff --git a/src/main/java/org/apache/bcel/classfile/Attribute.java b/src/main/java/org/apache/bcel/classfile/Attribute.java index d78c5f562b..90246fa422 100644 --- a/src/main/java/org/apache/bcel/classfile/Attribute.java +++ b/src/main/java/org/apache/bcel/classfile/Attribute.java @@ -199,6 +199,8 @@ public static Attribute readAttribute(final DataInput dataInput, final ConstantP return new NestMembers(nameIndex, length, dataInput, constantPool); case Const.ATTR_RECORD: return new Record(nameIndex, length, dataInput, constantPool); + case Const.ATTR_PERMITTED_SUBCLASSES: + return new PermittedSubclasses(nameIndex, length, dataInput, constantPool); default: // Never reached throw new IllegalStateException("Unrecognized attribute type tag parsed: " + tag); diff --git a/src/main/java/org/apache/bcel/classfile/DescendingVisitor.java b/src/main/java/org/apache/bcel/classfile/DescendingVisitor.java index 45180804d9..37f72df782 100644 --- a/src/main/java/org/apache/bcel/classfile/DescendingVisitor.java +++ b/src/main/java/org/apache/bcel/classfile/DescendingVisitor.java @@ -496,6 +496,14 @@ public void visitNestMembers(final NestMembers obj) { stack.pop(); } + /** @since 6.13.0 */ + @Override + public void visitPermittedSubclasses(final PermittedSubclasses obj) { + stack.push(obj); + obj.accept(visitor); + stack.pop(); + } + /** * @since 6.0 */ diff --git a/src/main/java/org/apache/bcel/classfile/EmptyVisitor.java b/src/main/java/org/apache/bcel/classfile/EmptyVisitor.java index 7a16e9ba1e..7a5165bdaf 100644 --- a/src/main/java/org/apache/bcel/classfile/EmptyVisitor.java +++ b/src/main/java/org/apache/bcel/classfile/EmptyVisitor.java @@ -284,6 +284,11 @@ public void visitNestHost(final NestHost obj) { public void visitNestMembers(final NestMembers obj) { } + /** @since 6.13.0 */ + @Override + public void visitPermittedSubclasses(final PermittedSubclasses obj) { + } + /** * @since 6.0 */ diff --git a/src/main/java/org/apache/bcel/classfile/PermittedSubclasses.java b/src/main/java/org/apache/bcel/classfile/PermittedSubclasses.java new file mode 100644 index 0000000000..62bc9fdafb --- /dev/null +++ b/src/main/java/org/apache/bcel/classfile/PermittedSubclasses.java @@ -0,0 +1,163 @@ +/* + * 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 java.util.Arrays; + +import org.apache.bcel.Const; +import org.apache.bcel.util.Args; +import org.apache.commons.lang3.ArrayUtils; + +/** + * This class is derived from Attribute and records the classes and interfaces that are permitted to extend or + * implement the current class or interface. There may be at most one PermittedSubclasses attribute in a ClassFile + * structure. + * + * @see Attribute + * @since 6.13.0 + */ +public final class PermittedSubclasses extends Attribute { + + private int[] classes; + + /** + * Constructs object from input stream. + * + * @param nameIndex Index in constant pool. + * @param length Content length in bytes. + * @param dataInput Input stream. + * @param constantPool Array of constants. + * @throws IOException if an I/O error occurs. + */ + PermittedSubclasses(final int nameIndex, final int length, final DataInput dataInput, final ConstantPool constantPool) throws IOException { + this(nameIndex, length, (int[]) null, constantPool); + classes = ClassParser.readU2U2Table(dataInput); + } + + /** + * @param nameIndex Index in constant pool. + * @param length Content length in bytes. + * @param classes Table of indices in constant pool. + * @param constantPool Array of constants. + */ + public PermittedSubclasses(final int nameIndex, final int length, final int[] classes, final ConstantPool constantPool) { + super(Const.ATTR_PERMITTED_SUBCLASSES, nameIndex, length, constantPool); + this.classes = ArrayUtils.nullToEmpty(classes); + Args.requireU2(this.classes.length, "classes.length"); + } + + /** + * Initialize from another object. Note that both objects use the same references (shallow copy). Use copy() for a + * physical copy. + * + * @param c Source to copy. + */ + public PermittedSubclasses(final PermittedSubclasses c) { + this(c.getNameIndex(), c.getLength(), c.getClasses(), c.getConstantPool()); + } + + /** + * Called by objects that are traversing the nodes of the tree implicitly defined by the contents of a Java class. + * I.e., the hierarchy of methods, fields, attributes, etc. spawns a tree of objects. + * + * @param v Visitor object. + */ + @Override + public void accept(final Visitor v) { + v.visitPermittedSubclasses(this); + } + + /** + * @return deep copy of this attribute. + */ + @Override + public Attribute copy(final ConstantPool constantPool) { + final PermittedSubclasses c = (PermittedSubclasses) clone(); + if (classes.length > 0) { + c.classes = classes.clone(); + } + c.setConstantPool(constantPool); + return c; + } + + /** + * Dumps PermittedSubclasses attribute to file stream in binary format. + * + * @param file Output file stream. + * @throws IOException if an I/O error occurs. + */ + @Override + public void dump(final DataOutputStream file) throws IOException { + super.dump(file); + file.writeShort(classes.length); + for (final int index : classes) { + file.writeShort(index); + } + } + + /** + * @return array of indices into constant pool of class names. + */ + public int[] getClasses() { + return classes; + } + + /** + * @return string array of class names. + */ + public String[] getClassNames() { + final String[] names = new String[classes.length]; + Arrays.setAll(names, i -> Utility.pathToPackage(super.getConstantPool().getConstantString(classes[i], Const.CONSTANT_Class))); + return names; + } + + /** + * @return Length of classes table. + */ + public int getNumberClasses() { + return classes.length; + } + + /** + * @param classes the list of class indexes Also redefines number_of_classes according to table length. + */ + public void setClasses(final int[] classes) { + this.classes = ArrayUtils.nullToEmpty(classes); + } + + /** + * @return String representation, that is, a list of permitted subclasses. + */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder(); + buf.append("PermittedSubclasses("); + buf.append(classes.length); + buf.append("):\n"); + for (final int index : classes) { + final String className = super.getConstantPool().getConstantString(index, Const.CONSTANT_Class); + buf.append(" ").append(Utility.compactClassName(className, false)).append("\n"); + } + return buf.substring(0, buf.length() - 1); // remove the last newline + } +} diff --git a/src/main/java/org/apache/bcel/classfile/Visitor.java b/src/main/java/org/apache/bcel/classfile/Visitor.java index 86fa8b572e..5df8e24332 100644 --- a/src/main/java/org/apache/bcel/classfile/Visitor.java +++ b/src/main/java/org/apache/bcel/classfile/Visitor.java @@ -411,6 +411,16 @@ default void visitNestMembers(final NestMembers obj) { // empty } + /** + * Visits a PermittedSubclasses attribute. + * + * @param obj the attribute. + * @since 6.13.0 + */ + default void visitPermittedSubclasses(final PermittedSubclasses obj) { + // empty + } + /** * Visits a ParameterAnnotations attribute. * diff --git a/src/main/java/org/apache/bcel/verifier/statics/StringRepresentation.java b/src/main/java/org/apache/bcel/verifier/statics/StringRepresentation.java index 88b0d53cda..13f0604918 100644 --- a/src/main/java/org/apache/bcel/verifier/statics/StringRepresentation.java +++ b/src/main/java/org/apache/bcel/verifier/statics/StringRepresentation.java @@ -58,6 +58,7 @@ import org.apache.bcel.classfile.Method; import org.apache.bcel.classfile.MethodParameters; import org.apache.bcel.classfile.NestMembers; +import org.apache.bcel.classfile.PermittedSubclasses; import org.apache.bcel.classfile.Node; import org.apache.bcel.classfile.ParameterAnnotationEntry; import org.apache.bcel.classfile.ParameterAnnotations; @@ -385,6 +386,14 @@ public void visitNestMembers(final NestMembers obj) { tostring = toString(obj); } + /** + * @since 6.13.0 + */ + @Override + public void visitPermittedSubclasses(final PermittedSubclasses obj) { + tostring = toString(obj); + } + /** * @since 6.0 */ diff --git a/src/test/java/org/apache/bcel/classfile/PermittedSubclassesTest.java b/src/test/java/org/apache/bcel/classfile/PermittedSubclassesTest.java new file mode 100644 index 0000000000..8ad2f32efa --- /dev/null +++ b/src/test/java/org/apache/bcel/classfile/PermittedSubclassesTest.java @@ -0,0 +1,72 @@ +/* + * 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 org.apache.bcel.AbstractTest; +import org.apache.bcel.verifier.statics.StringRepresentation; +import org.junit.jupiter.api.Test; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Arrays; +import java.util.List; +import java.util.jar.JarEntry; +import java.util.jar.JarFile; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +class PermittedSubclassesTest extends AbstractTest { + + private static final String SEALED_JAR_PATH = "src/test/resources/sealed/sealed-demo-jdk21.0.8.jar"; + + private static final String SHAPE_CLASS_ENTRY = "org/jd/core/v1/SealedDemo$Shape.class"; + + private JavaClass parseJarClass(final String entryName) throws IOException { + try (JarFile jar = new JarFile(SEALED_JAR_PATH)) { + final JarEntry entry = jar.getJarEntry(entryName); + assertNotNull(entry, "Missing jar entry: " + entryName); + try (InputStream inputStream = jar.getInputStream(entry)) { + return new ClassParser(inputStream, entryName).parse(); + } + } + } + + @Test + void readsPermittedSubclassesAttribute() throws IOException { + final JavaClass clazz = parseJarClass(SHAPE_CLASS_ENTRY); + final Attribute[] attributes = findAttribute("PermittedSubclasses", clazz); + assertEquals(1, attributes.length, "Expected one PermittedSubclasses attribute"); + final PermittedSubclasses permittedSubclasses = (PermittedSubclasses) attributes[0]; + final List classNames = Arrays.asList(permittedSubclasses.getClassNames()); + assertEquals(2, classNames.size(), "Expected two permitted subclasses"); + assertTrue(classNames.contains("org.jd.core.v1.SealedDemo$Circle"), "Missing permitted subclass Circle"); + assertTrue(classNames.contains("org.jd.core.v1.SealedDemo$Rectangle"), "Missing permitted subclass Rectangle"); + } + + @Test + void stringRepresentationHandlesPermittedSubclasses() throws IOException { + final JavaClass clazz = parseJarClass(SHAPE_CLASS_ENTRY); + final Attribute[] attributes = findAttribute("PermittedSubclasses", clazz); + final PermittedSubclasses permittedSubclasses = (PermittedSubclasses) attributes[0]; + assertEquals(permittedSubclasses.toString(), new StringRepresentation(permittedSubclasses).toString()); + } +} diff --git a/src/test/resources/sealed/SealedDemo.java b/src/test/resources/sealed/SealedDemo.java new file mode 100644 index 0000000000..cda1f71b9f --- /dev/null +++ b/src/test/resources/sealed/SealedDemo.java @@ -0,0 +1,43 @@ +package org.jd.core.v1; + +public class SealedDemo { + + sealed interface Shape permits Circle, Rectangle { + double area(); + } + + static final class Circle implements Shape { + private final double radius; + + Circle(double radius) { + this.radius = radius; + } + + @Override + public double area() { + return Math.PI * radius * radius; + } + } + + static non-sealed class Rectangle implements Shape { + private final double width; + private final double height; + + Rectangle(double width, double height) { + this.width = width; + this.height = height; + } + + @Override + public double area() { + return width * height; + } + } + + double sealedSwitch(Shape shape) { + return switch (shape) { + case Circle circle -> circle.area(); + case Rectangle rectangle -> rectangle.area(); + }; + } +} diff --git a/src/test/resources/sealed/sealed-demo-jdk21.0.8.jar b/src/test/resources/sealed/sealed-demo-jdk21.0.8.jar new file mode 100644 index 0000000000000000000000000000000000000000..46d49ef985cb38e3a989d3c1665d65c81e90cd59 GIT binary patch literal 2788 zcma)82{e>#8y@>Mbqu4XKfW(M`!X|V8j3P@#)u*NU}Eg+)Qo&tz6L|~B~zwBLks;W zV@)ZBvXn?fiIT`t$&js-Z|3j+;`E=K|9a1R&hwu4dG7l@_jT^;x$Mvag5m&xC;;GX zjPd|%f*3#$fH8AKX<6Bt!@fNL0PMJ1!2nTF(f`>B<{ta86@#+1GBY!MhQ|sRjbVX8&33x1^L2!!ifYJSsUg+z=sfgO$njl ziY9?XpAZ7nCj@`&SW*rS-3kX&U%f9K2^tw@ESx;=U?<{sM;dJJWQw1;-!@wfz1clv zJ+xYHY9|O=B&96PrqLEAO$>jl~SmDKi`03d^8k&8CwJ)J}yZIB4N|;UO`h)s63J{&0 z3hA~9@F(_!bL)BC-bJf-voTr8%nLR(A7?Kfaec}i+_`)I8N5Bewl8-`?m2am;p0g82*iT!e3}jTbE&~cVvv%YTF;5 zf@_D@BM>BaM}q~l{#zwhnIqc8sg6R&Dwk!7J6SsHaUawv=JCof5gSY70{{Z~x8hZ8 zOJ1=ApX2y2|9_~>uzz9QY9wjcR};9q^y!~X{ePOh5J?z4uaJTQr&97MSue&6V5uy1iKvGV0gJLC2+^r+gW5-2;!ygt(6x7F0LPYKVkJ3!)BbgZ&U6L-2O zc70Pbsyy6c*Oq+BQmV5R9Dks+zE$c)F5m4Q)-}dNyn_>zQ}7zrE`w)OqahxAmp)6B z-Q}dm+*wM0Z84(9#Jgr5lby7`$8T=OR(z$YosB=&viE|nlF5DtW8q2Nb8;Q;;huL~ z7gd~2w9Gwit*4ZG(Gc%;CLp{KF3zM!)z|lHl+B#hY4kLM=|7mPa$OPRQ4BU}^GfGZ z9KR*SN?TIw5P*;P@8puQF}AHnz@%a{-O7ZSL=g-zq6mdRA_e=!*}{_g?BhrCP5XfK zi-xii+nbq^wi;}8&vdQz#?|*9i+f;zWj&`UPAN}@L^e0kjC0g&p zS`IvVqEeGiT?j$cclRR(#lIw`g>?mju1R-mzplFd4pWxYBqV$Ah)nXdQ{m%R@2yhm zjT6~k;lPg6fQ)fqtR+9_OrxP9BqS!4x#Ch{m>#i*Q_$669|2LxMQgK9J7Q(!SA}?e zgob}@Smbsoj@!#$OW^NY_3^v*WjH>^N~6Gr7@EBNwID@Js*<-p6|rWM z@s-$hpN6sm3et|WdP6X8*VE}%UqfdUj6*>+r3v!y?_NzAE1C@=P^S*fNt6o- z;eaD5Dnhm|vpj=J#%5@{%vGQd(728fw%zv&wjbp`;kV%HX-Bv?g35iamW@A zlym)0s-zM;<*kU0eDtVbDpPnCK~S~mICx9B)l#6D^{+%RJ)K>xqYW_-w>0QrokZgp z&Vx;&uIQ_(mz5l;MQ~isUK={xt>U{2UZW}At|eNo9r#Q;-1YjKp+>A^*mHIL4=9`D z$lX!k;e46>CRj#)77l@nwJ1Xz$zp-07N=YK9^r!B%WAU^-*nYU%7>9AIZod#C$M+-Xm%oYN&j#E?r<+pmO;oM=}G|Gt~;u$e{~JK{)*BV?lCjGI8^Q zwDy5RM$t}lk202jFOfO%PXCFniD9`ZJ56^HRQN7kZnR~R154>%@%a{eya~1Y!)HH! zR`bE@jSEEdZ@4q4qgT}Yw_9oUx)H7OVrg`|l$x8N5;-uv*U}?18tNlEs5&WFaZ+*x zdf>_fs&U03RH!q`Bd2~D6!+v!v;Z~dFZzqg}JFVtqm{rCRj%sU{=eLA>eDJ;hO`WuH> BQsDpq literal 0 HcmV?d00001 From d4b526cb981c2d54313d0059e726a46e7aff23f1 Mon Sep 17 00:00:00 2001 From: nbauma109 Date: Sun, 1 Feb 2026 15:25:43 +0100 Subject: [PATCH 2/6] fix checkstyle issues --- src/main/java/org/apache/bcel/Const.java | 4 ++-- .../bcel/verifier/statics/StringRepresentation.java | 2 +- .../bcel/classfile/PermittedSubclassesTest.java | 12 ++++++------ 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/apache/bcel/Const.java b/src/main/java/org/apache/bcel/Const.java index 8d188c2271..8e5a16b147 100644 --- a/src/main/java/org/apache/bcel/Const.java +++ b/src/main/java/org/apache/bcel/Const.java @@ -3168,8 +3168,8 @@ public final class Const { /** Attribute constant for Record. */ public static final byte ATTR_RECORD = 27; - /** Attribute constant for PermittedSubclasses. - * @since 6.13.0 + /** Attribute constant for PermittedSubclasses. + * @since 6.13.0 */ public static final byte ATTR_PERMITTED_SUBCLASSES = 28; diff --git a/src/main/java/org/apache/bcel/verifier/statics/StringRepresentation.java b/src/main/java/org/apache/bcel/verifier/statics/StringRepresentation.java index 13f0604918..603f8c12f8 100644 --- a/src/main/java/org/apache/bcel/verifier/statics/StringRepresentation.java +++ b/src/main/java/org/apache/bcel/verifier/statics/StringRepresentation.java @@ -58,8 +58,8 @@ import org.apache.bcel.classfile.Method; import org.apache.bcel.classfile.MethodParameters; import org.apache.bcel.classfile.NestMembers; -import org.apache.bcel.classfile.PermittedSubclasses; import org.apache.bcel.classfile.Node; +import org.apache.bcel.classfile.PermittedSubclasses; import org.apache.bcel.classfile.ParameterAnnotationEntry; import org.apache.bcel.classfile.ParameterAnnotations; import org.apache.bcel.classfile.Record; diff --git a/src/test/java/org/apache/bcel/classfile/PermittedSubclassesTest.java b/src/test/java/org/apache/bcel/classfile/PermittedSubclassesTest.java index 8ad2f32efa..503349caf1 100644 --- a/src/test/java/org/apache/bcel/classfile/PermittedSubclassesTest.java +++ b/src/test/java/org/apache/bcel/classfile/PermittedSubclassesTest.java @@ -19,9 +19,9 @@ package org.apache.bcel.classfile; -import org.apache.bcel.AbstractTest; -import org.apache.bcel.verifier.statics.StringRepresentation; -import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.IOException; import java.io.InputStream; @@ -30,9 +30,9 @@ import java.util.jar.JarEntry; import java.util.jar.JarFile; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; +import org.apache.bcel.AbstractTest; +import org.apache.bcel.verifier.statics.StringRepresentation; +import org.junit.jupiter.api.Test; class PermittedSubclassesTest extends AbstractTest { From 3c066e6100a698b1152457421986fa3ea11bfe9a Mon Sep 17 00:00:00 2001 From: nbauma109 Date: Sun, 1 Feb 2026 15:29:32 +0100 Subject: [PATCH 3/6] fix checksyle issues --- .../org/apache/bcel/verifier/statics/StringRepresentation.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/apache/bcel/verifier/statics/StringRepresentation.java b/src/main/java/org/apache/bcel/verifier/statics/StringRepresentation.java index 603f8c12f8..917d8db06b 100644 --- a/src/main/java/org/apache/bcel/verifier/statics/StringRepresentation.java +++ b/src/main/java/org/apache/bcel/verifier/statics/StringRepresentation.java @@ -59,9 +59,9 @@ import org.apache.bcel.classfile.MethodParameters; import org.apache.bcel.classfile.NestMembers; import org.apache.bcel.classfile.Node; -import org.apache.bcel.classfile.PermittedSubclasses; import org.apache.bcel.classfile.ParameterAnnotationEntry; import org.apache.bcel.classfile.ParameterAnnotations; +import org.apache.bcel.classfile.PermittedSubclasses; import org.apache.bcel.classfile.Record; import org.apache.bcel.classfile.RecordComponentInfo; import org.apache.bcel.classfile.Signature; From cd08764855f4131fd6bf2299bcefe522b1c04c5b Mon Sep 17 00:00:00 2001 From: nbauma109 Date: Sun, 1 Feb 2026 16:57:58 +0100 Subject: [PATCH 4/6] Added javadoc descriptions --- .../apache/bcel/classfile/PermittedSubclasses.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/main/java/org/apache/bcel/classfile/PermittedSubclasses.java b/src/main/java/org/apache/bcel/classfile/PermittedSubclasses.java index 62bc9fdafb..b5e48f8c65 100644 --- a/src/main/java/org/apache/bcel/classfile/PermittedSubclasses.java +++ b/src/main/java/org/apache/bcel/classfile/PermittedSubclasses.java @@ -55,6 +55,8 @@ public final class PermittedSubclasses extends Attribute { } /** + * Constructs object from table of class indices in constant pool. + * * @param nameIndex Index in constant pool. * @param length Content length in bytes. * @param classes Table of indices in constant pool. @@ -88,6 +90,8 @@ public void accept(final Visitor v) { } /** + * Creates a deep clone of this object given constant pool. + * * @return deep copy of this attribute. */ @Override @@ -116,6 +120,8 @@ public void dump(final DataOutputStream file) throws IOException { } /** + * Gets the class indices in constant pool. + * * @return array of indices into constant pool of class names. */ public int[] getClasses() { @@ -123,6 +129,8 @@ public int[] getClasses() { } /** + * Gets permitted class names. + * * @return string array of class names. */ public String[] getClassNames() { @@ -132,6 +140,8 @@ public String[] getClassNames() { } /** + * Gets the number of classes. + * * @return Length of classes table. */ public int getNumberClasses() { @@ -139,6 +149,8 @@ public int getNumberClasses() { } /** + * Sets class indices. + * * @param classes the list of class indexes Also redefines number_of_classes according to table length. */ public void setClasses(final int[] classes) { @@ -146,6 +158,8 @@ public void setClasses(final int[] classes) { } /** + * String representation of PermittedSubclasses (for debugging purposes). + * * @return String representation, that is, a list of permitted subclasses. */ @Override From b4e90e5b4c49ac4545aa5267f3bcfb1a88376740 Mon Sep 17 00:00:00 2001 From: nbauma109 Date: Sun, 1 Feb 2026 17:03:36 +0100 Subject: [PATCH 5/6] added javadoc --- .../org/apache/bcel/verifier/statics/StringRepresentation.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/org/apache/bcel/verifier/statics/StringRepresentation.java b/src/main/java/org/apache/bcel/verifier/statics/StringRepresentation.java index 917d8db06b..e9329f909c 100644 --- a/src/main/java/org/apache/bcel/verifier/statics/StringRepresentation.java +++ b/src/main/java/org/apache/bcel/verifier/statics/StringRepresentation.java @@ -387,6 +387,8 @@ public void visitNestMembers(final NestMembers obj) { } /** + * Visits PermittedSubclasses attribute. + * * @since 6.13.0 */ @Override From bb70924705d298207b5b9ff1924f8edf4c1827fb Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Sun, 1 Feb 2026 14:46:00 -0500 Subject: [PATCH 6/6] Javadoc Updated documentation for ATTR_PERMITTED_SUBCLASSES constant. --- src/main/java/org/apache/bcel/Const.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/apache/bcel/Const.java b/src/main/java/org/apache/bcel/Const.java index 8e5a16b147..60336ef0e5 100644 --- a/src/main/java/org/apache/bcel/Const.java +++ b/src/main/java/org/apache/bcel/Const.java @@ -3168,8 +3168,10 @@ public final class Const { /** Attribute constant for Record. */ public static final byte ATTR_RECORD = 27; - /** Attribute constant for PermittedSubclasses. - * @since 6.13.0 + /** + * Attribute constant for PermittedSubclasses. + * + * @since 6.13.0 */ public static final byte ATTR_PERMITTED_SUBCLASSES = 28;