You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "garydgregory (via GitHub)" <gi...@apache.org> on 2026/06/15 21:42:34 UTC

Re: [PR] Make wide flag thread-local in Utility.codeToString [commons-bcel]

garydgregory commented on code in PR #502:
URL: https://github.com/apache/commons-bcel/pull/502#discussion_r3416739279


##########
src/test/java/org/apache/bcel/classfile/UtilityTest.java:
##########
@@ -178,4 +180,31 @@ void testSignatureToStringWithGenerics() throws Exception {
         assertEquals("<K extends Object, V extends Object> extends Object",
                 Utility.signatureToString("<K:Ljava/lang/Object;V:Ljava/lang/Object;>Ljava/lang/Object;"), "class signature");
     }
+
+    @Test
+    void testCodeToStringWideIsThreadLocal() throws Exception {
+        // A WIDE opcode disassembled on one thread must not change how the next
+        // local-variable instruction is decoded on another thread.
+        final Thread setter = new Thread(() -> {
+            try {
+                Utility.codeToString(new ByteSequence(new byte[] {(byte) Const.WIDE}), new ConstantPool(), false);
+            } catch (final Exception e) {
+                throw new AssertionError(e);

Review Comment:
   You could call `org.junit.jupiter.api.Assertions.fail(String, Throwable)` here.



##########
src/test/java/org/apache/bcel/classfile/UtilityTest.java:
##########
@@ -178,4 +180,31 @@ void testSignatureToStringWithGenerics() throws Exception {
         assertEquals("<K extends Object, V extends Object> extends Object",
                 Utility.signatureToString("<K:Ljava/lang/Object;V:Ljava/lang/Object;>Ljava/lang/Object;"), "class signature");
     }
+
+    @Test
+    void testCodeToStringWideIsThreadLocal() throws Exception {
+        // A WIDE opcode disassembled on one thread must not change how the next
+        // local-variable instruction is decoded on another thread.
+        final Thread setter = new Thread(() -> {
+            try {
+                Utility.codeToString(new ByteSequence(new byte[] {(byte) Const.WIDE}), new ConstantPool(), false);
+            } catch (final Exception e) {
+                throw new AssertionError(e);
+            }
+        });
+        setter.start();
+        setter.join();
+        final AtomicReference<String> reader = new AtomicReference<>();
+        final Thread thread = new Thread(() -> {
+            try {
+                // iload with a single index byte; the trailing 0x02 must stay unread.
+                reader.set(Utility.codeToString(new ByteSequence(new byte[] {(byte) Const.ILOAD, 1, 2}), new ConstantPool(), false));
+            } catch (final Exception e) {
+                throw new AssertionError(e);

Review Comment:
   You could call `org.junit.jupiter.api.Assertions.fail(String, Throwable)` here.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org