You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2026/06/10 11:17:28 UTC

(camel) branch main updated: CAMEL-23635: camel-jbang - Fix ArrayIndexOutOfBoundsException in TUI shell panel

This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/main by this push:
     new 8770ef1cd764 CAMEL-23635: camel-jbang - Fix ArrayIndexOutOfBoundsException in TUI shell panel
8770ef1cd764 is described below

commit 8770ef1cd764d0f49b8d0ebae271167db65c96a6
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Wed Jun 10 13:03:36 2026 +0200

    CAMEL-23635: camel-jbang - Fix ArrayIndexOutOfBoundsException in TUI shell panel
    
    Guard against concurrent ScreenTerminal buffer access during resize.
    The shell thread writes output while the render thread may resize the
    buffer, causing poke() to compute a negative index.
    
    Co-Authored-By: Claude <no...@anthropic.com>
    Signed-off-by: Claus Ibsen <cl...@gmail.com>
---
 .../dsl/jbang/core/commands/tui/ShellPanel.java    | 31 +++++++++++++++++-----
 1 file changed, 24 insertions(+), 7 deletions(-)

diff --git a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/ShellPanel.java b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/ShellPanel.java
index 2af50c12cf26..7b5943da835a 100644
--- a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/ShellPanel.java
+++ b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/ShellPanel.java
@@ -132,8 +132,8 @@ class ShellPanel {
                 if (bytes != null && bytes.length > 0) {
                     virtualTerminal.processInputBytes(bytes);
                 }
-            } catch (IOException e) {
-                // terminal closed
+            } catch (IOException | ArrayIndexOutOfBoundsException e) {
+                // terminal closed or buffer resized concurrently
             }
         }
         return true;
@@ -190,10 +190,15 @@ class ShellPanel {
             return;
         }
 
-        // Dump screen buffer
+        // Dump screen buffer (may race with shell thread writing)
         long[] screen = new long[innerWidth * innerHeight];
         int[] cursor = new int[2];
-        screenTerminal.dump(screen, cursor);
+        try {
+            screenTerminal.dump(screen, cursor);
+        } catch (ArrayIndexOutOfBoundsException e) {
+            // buffer resized concurrently — skip this frame
+            return;
+        }
 
         // Convert to TamboUI lines
         List<Line> lines = new ArrayList<>(innerHeight);
@@ -469,21 +474,33 @@ class ShellPanel {
         @Override
         public void write(int b) throws IOException {
             if (delegate != null) {
-                delegate.write(b);
+                try {
+                    delegate.write(b);
+                } catch (ArrayIndexOutOfBoundsException e) {
+                    // ScreenTerminal buffer resized concurrently — safe to ignore
+                }
             }
         }
 
         @Override
         public void write(byte[] b, int off, int len) throws IOException {
             if (delegate != null) {
-                delegate.write(b, off, len);
+                try {
+                    delegate.write(b, off, len);
+                } catch (ArrayIndexOutOfBoundsException e) {
+                    // ScreenTerminal buffer resized concurrently — safe to ignore
+                }
             }
         }
 
         @Override
         public void flush() throws IOException {
             if (delegate != null) {
-                delegate.flush();
+                try {
+                    delegate.flush();
+                } catch (ArrayIndexOutOfBoundsException e) {
+                    // ScreenTerminal buffer resized concurrently — safe to ignore
+                }
             }
         }