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 d7596d0c Sort members.
d7596d0c is described below

commit d7596d0c7c3626d9988f0f938a6e37d86060426d
Author: Gary Gregory <[email protected]>
AuthorDate: Mon Jun 15 21:28:53 2026 +0000

    Sort members.
---
 src/main/java/org/apache/bcel/Repository.java      | 12 +--
 src/main/java/org/apache/bcel/util/BCELifier.java  | 22 ++---
 .../java/org/apache/bcel/util/BCELifierTest.java   | 94 +++++++++++-----------
 3 files changed, 64 insertions(+), 64 deletions(-)

diff --git a/src/main/java/org/apache/bcel/Repository.java 
b/src/main/java/org/apache/bcel/Repository.java
index 21a7ef11..a0f78350 100644
--- a/src/main/java/org/apache/bcel/Repository.java
+++ b/src/main/java/org/apache/bcel/Repository.java
@@ -35,12 +35,6 @@ public abstract class Repository {
 
     private static org.apache.bcel.util.Repository repository = 
SyntheticRepository.getInstance();
 
-    /**
-     * Constructs a new Repository.
-     */
-    public Repository() {
-    }
-
     /**
      * Adds clazz to repository if there isn't an equally named class already 
in there.
      *
@@ -276,4 +270,10 @@ public abstract class Repository {
     public static void setRepository(final org.apache.bcel.util.Repository 
rep) {
         repository = rep;
     }
+
+    /**
+     * Constructs a new Repository.
+     */
+    public Repository() {
+    }
 }
diff --git a/src/main/java/org/apache/bcel/util/BCELifier.java 
b/src/main/java/org/apache/bcel/util/BCELifier.java
index e6039d88..eb5fb507 100644
--- a/src/main/java/org/apache/bcel/util/BCELifier.java
+++ b/src/main/java/org/apache/bcel/util/BCELifier.java
@@ -71,6 +71,17 @@ public class BCELifier extends 
org.apache.bcel.classfile.EmptyVisitor {
     private static final String BASE_PACKAGE = 
Const.class.getPackage().getName();
     private static final String CONSTANT_PREFIX = Const.class.getSimpleName() 
+ ".";
 
+    private static String[] escape(final String[] names) {
+        if (names == null) {
+            return null;
+        }
+        final String[] escaped = new String[names.length];
+        for (int i = 0; i < names.length; i++) {
+            escaped[i] = names[i] == null ? null : 
Utility.convertString(names[i]);
+        }
+        return escaped;
+    }
+
     // Needs to be accessible from unit test code
     static JavaClass getJavaClass(final String name) throws 
ClassNotFoundException, IOException {
         JavaClass javaClass;
@@ -96,17 +107,6 @@ public class BCELifier extends 
org.apache.bcel.classfile.EmptyVisitor {
         bcelifier.start();
     }
 
-    private static String[] escape(final String[] names) {
-        if (names == null) {
-            return null;
-        }
-        final String[] escaped = new String[names.length];
-        for (int i = 0; i < names.length; i++) {
-            escaped[i] = names[i] == null ? null : 
Utility.convertString(names[i]);
-        }
-        return escaped;
-    }
-
     static String printArgumentTypes(final Type[] argTypes) {
         if (argTypes.length == 0) {
             return "Type.NO_ARGS";
diff --git a/src/test/java/org/apache/bcel/util/BCELifierTest.java 
b/src/test/java/org/apache/bcel/util/BCELifierTest.java
index 2f4e1733..94b845ca 100644
--- a/src/test/java/org/apache/bcel/util/BCELifierTest.java
+++ b/src/test/java/org/apache/bcel/util/BCELifierTest.java
@@ -176,6 +176,23 @@ class BCELifierTest extends AbstractTest {
         }
     }
 
+    @Test
+    void testClassNamesEscapedInOutput() throws Exception {
+        // Superclass and source file names are constant-pool derived and can 
hold any UTF-8.
+        final String evilSuper = "java.lang.Object\"); System.exit(1); _cg = 
new ClassGen(\"x";
+        final String evilSource = "Example.java\"); System.exit(2); String s = 
(\"";
+        final ClassGen cg = new ClassGen("Example", evilSuper, evilSource, 
Const.ACC_PUBLIC | Const.ACC_SUPER, new String[] {});
+
+        final ByteArrayOutputStream os = new ByteArrayOutputStream();
+        new BCELifier(cg.getJavaClass(), os).start();
+        final String source = new String(os.toByteArray(), 
StandardCharsets.UTF_8);
+
+        assertTrue(source.contains(Utility.convertString(evilSuper)), source);
+        assertTrue(source.contains(Utility.convertString(evilSource)), source);
+        assertFalse(source.contains('"' + evilSuper + '"'), source);
+        assertFalse(source.contains('"' + evilSource + '"'), source);
+    }
+
     private void testClassOnPath(final String javaClassFileName) throws 
Exception {
         final File workDir = new File("target", getClass().getSimpleName());
         Files.createDirectories(workDir.getParentFile().toPath());
@@ -217,6 +234,30 @@ class BCELifierTest extends AbstractTest {
         assertEquals(canonHashRef(javapOutInital), canonHashRef(javapOutput));
     }
 
+    @Test
+    void testCreateInvokeEscapesConstantPoolName() throws Exception {
+        // A hostile constant pool can hold any UTF-8 as a referenced method 
name.
+        final String evilName = "evil\"); System.exit(1); il.append(\"";
+        final ClassGen cg = new ClassGen("Example", "java.lang.Object", 
"Example.java", Const.ACC_PUBLIC | Const.ACC_SUPER, new String[] {});
+        final ConstantPoolGen cp = cg.getConstantPool();
+        final InstructionFactory factory = new InstructionFactory(cg, cp);
+        final InstructionList il = new InstructionList();
+        il.append(InstructionConst.ALOAD_0);
+        il.append(factory.createInvoke("java.lang.Object", evilName, 
Type.VOID, Type.NO_ARGS, Const.INVOKEVIRTUAL));
+        il.append(InstructionConst.RETURN);
+        final MethodGen mg = new MethodGen(Const.ACC_PUBLIC, Type.VOID, 
Type.NO_ARGS, new String[] {}, "m", "Example", il, cp);
+        mg.setMaxStack();
+        mg.setMaxLocals();
+        cg.addMethod(mg.getMethod());
+
+        final ByteArrayOutputStream os = new ByteArrayOutputStream();
+        new BCELifier(cg.getJavaClass(), os).start();
+        final String source = new String(os.toByteArray(), 
StandardCharsets.UTF_8);
+
+        
assertTrue(source.contains("_factory.createInvoke(\"java.lang.Object\", \"" + 
Utility.convertString(evilName) + "\", "), source);
+        assertFalse(source.contains('"' + evilName + '"'), source);
+    }
+
     @Test
     void testHelloWorld() throws Exception {
         HelloWorldCreator.main(new String[] {});
@@ -280,38 +321,6 @@ class BCELifierTest extends AbstractTest {
         }
     }
 
-    @ParameterizedTest
-    @ValueSource(strings = { "StackMapExample", "StackMapExample2" })
-    void testStackMap(final String className) throws Exception {
-        testJavapCompare(className);
-        final File workDir = new File("target");
-        assertEquals("Hello World" + EOL, exec(workDir, getAppJava(), "-cp", 
CLASSPATH, className, "Hello"));
-    }
-
-    @Test
-    void testCreateInvokeEscapesConstantPoolName() throws Exception {
-        // A hostile constant pool can hold any UTF-8 as a referenced method 
name.
-        final String evilName = "evil\"); System.exit(1); il.append(\"";
-        final ClassGen cg = new ClassGen("Example", "java.lang.Object", 
"Example.java", Const.ACC_PUBLIC | Const.ACC_SUPER, new String[] {});
-        final ConstantPoolGen cp = cg.getConstantPool();
-        final InstructionFactory factory = new InstructionFactory(cg, cp);
-        final InstructionList il = new InstructionList();
-        il.append(InstructionConst.ALOAD_0);
-        il.append(factory.createInvoke("java.lang.Object", evilName, 
Type.VOID, Type.NO_ARGS, Const.INVOKEVIRTUAL));
-        il.append(InstructionConst.RETURN);
-        final MethodGen mg = new MethodGen(Const.ACC_PUBLIC, Type.VOID, 
Type.NO_ARGS, new String[] {}, "m", "Example", il, cp);
-        mg.setMaxStack();
-        mg.setMaxLocals();
-        cg.addMethod(mg.getMethod());
-
-        final ByteArrayOutputStream os = new ByteArrayOutputStream();
-        new BCELifier(cg.getJavaClass(), os).start();
-        final String source = new String(os.toByteArray(), 
StandardCharsets.UTF_8);
-
-        
assertTrue(source.contains("_factory.createInvoke(\"java.lang.Object\", \"" + 
Utility.convertString(evilName) + "\", "), source);
-        assertFalse(source.contains('"' + evilName + '"'), source);
-    }
-
     @Test
     void testMethodNameEscapedInOutput() throws Exception {
         // A hostile constant pool can hold any UTF-8 as a method name.
@@ -333,21 +342,12 @@ class BCELifierTest extends AbstractTest {
         assertFalse(source.contains('"' + evilName + '"'), source);
     }
 
-    @Test
-    void testClassNamesEscapedInOutput() throws Exception {
-        // Superclass and source file names are constant-pool derived and can 
hold any UTF-8.
-        final String evilSuper = "java.lang.Object\"); System.exit(1); _cg = 
new ClassGen(\"x";
-        final String evilSource = "Example.java\"); System.exit(2); String s = 
(\"";
-        final ClassGen cg = new ClassGen("Example", evilSuper, evilSource, 
Const.ACC_PUBLIC | Const.ACC_SUPER, new String[] {});
-
-        final ByteArrayOutputStream os = new ByteArrayOutputStream();
-        new BCELifier(cg.getJavaClass(), os).start();
-        final String source = new String(os.toByteArray(), 
StandardCharsets.UTF_8);
-
-        assertTrue(source.contains(Utility.convertString(evilSuper)), source);
-        assertTrue(source.contains(Utility.convertString(evilSource)), source);
-        assertFalse(source.contains('"' + evilSuper + '"'), source);
-        assertFalse(source.contains('"' + evilSource + '"'), source);
+    @ParameterizedTest
+    @ValueSource(strings = { "StackMapExample", "StackMapExample2" })
+    void testStackMap(final String className) throws Exception {
+        testJavapCompare(className);
+        final File workDir = new File("target");
+        assertEquals("Hello World" + EOL, exec(workDir, getAppJava(), "-cp", 
CLASSPATH, className, "Hello"));
     }
 
     @Test

Reply via email to