From 6b47111df490a0cfcb8a59bce1a7864ea4940de4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?JB=20Onofr=C3=A9?= Date: Sun, 25 Jan 2026 08:54:08 +0100 Subject: [PATCH] Catch StringIndexOutOfBoundException in ConsoleSessionImpl to workaround an issue in JLine --- .../apache/karaf/shell/impl/console/ConsoleSessionImpl.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/shell/core/src/main/java/org/apache/karaf/shell/impl/console/ConsoleSessionImpl.java b/shell/core/src/main/java/org/apache/karaf/shell/impl/console/ConsoleSessionImpl.java index d61509f3cdc..a14ee421778 100644 --- a/shell/core/src/main/java/org/apache/karaf/shell/impl/console/ConsoleSessionImpl.java +++ b/shell/core/src/main/java/org/apache/karaf/shell/impl/console/ConsoleSessionImpl.java @@ -465,6 +465,12 @@ private CharSequence readCommand(AtomicBoolean reading) throws UserInterruptExce } } catch (UserInterruptException e) { command = ""; // Do nothing + } catch (StringIndexOutOfBoundsException e) { + // Workaround for JLine CompletionMatcherImpl bug: Tab on empty line triggers + // substring(0, 1) on "" in defaultMatchers() before EMPTY_WORD_OPTIONS check. + // Re-prompt instead of exiting the shell. + LOGGER.debug("Completion on empty line triggered known JLine edge case", e); + command = ""; } catch (Throwable t) { ShellUtil.logException(this, t); } finally {