[Java] Fix undefined behavior in HumanObjectPeerTest
authorMatt Corallo <git@bluematt.me>
Thu, 28 Jul 2022 03:29:27 +0000 (03:29 +0000)
committerMatt Corallo <git@bluematt.me>
Thu, 28 Jul 2022 03:29:27 +0000 (03:29 +0000)
CI somehow convinced the access to custom_messages_to_send to
trigger an `ArrayIndexOutOfBoundsException`, which should not be
possible except in race cases due to threading issues. Adding the
missing synchronized block should address it.

src/test/java/org/ldk/HumanObjectPeerTest.java

index e2af30439371a8f5bdc742b2cf3e8f9f9c942660..751f198fe4fe4c46368a6b8b799342ebecc0a01f 100644 (file)
@@ -1054,7 +1054,9 @@ class HumanObjectPeerTestInstance {
         // so we cannot exchange custom messages with it
         if (!use_chan_manager_constructor) {
             byte[] custom_message_bytes = new byte[]{0x42, 0x44, 0x43, 0x00};
-            state.peer1.custom_messages_to_send.add(custom_message_bytes);
+            synchronized(state.peer1.custom_messages_to_send) {
+                state.peer1.custom_messages_to_send.add(custom_message_bytes);
+            }
             state.peer1.peer_manager.process_events();
             synchronized (state.peer2.received_custom_messages) {
                 while (true) {