This is an automated email from the ASF dual-hosted git repository.
jbonofre pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/karaf.git
The following commit(s) were added to refs/heads/main by this push:
new 75117bb237 fix(shell): prevent LinkageError from killing the local
console thread (#2313)
75117bb237 is described below
commit 75117bb2378567bb480376aad7a87416d5c9ec38
Author: JB Onofré <[email protected]>
AuthorDate: Sat Mar 14 12:05:44 2026 +0100
fix(shell): prevent LinkageError from killing the local console thread
(#2313)
When the JLine bundle is refreshed during runtime (e.g., due to feature
install/update), the bundle classloader changes and AttributedString may
be loaded by two different classloaders. This causes a LinkageError in
ShellUtil.applyStyle().
The logException() error handler only caught Exception, not Error, so
the LinkageError escaped and killed the console thread. Broaden the
catch to Throwable so classloading errors during exception display are
handled gracefully.
Also set command to empty string in readCommand()'s catch-all handler
so transient errors re-prompt instead of exiting the session.
---
.../java/org/apache/karaf/shell/impl/console/ConsoleSessionImpl.java | 1 +
.../core/src/main/java/org/apache/karaf/shell/support/ShellUtil.java | 5 +++--
2 files changed, 4 insertions(+), 2 deletions(-)
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 a14ee42177..61a6aaec0c 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
@@ -473,6 +473,7 @@ public class ConsoleSessionImpl implements Session {
command = "";
} catch (Throwable t) {
ShellUtil.logException(this, t);
+ command = "";
} finally {
reading.set(false);
}
diff --git
a/shell/core/src/main/java/org/apache/karaf/shell/support/ShellUtil.java
b/shell/core/src/main/java/org/apache/karaf/shell/support/ShellUtil.java
index de871baf02..862a895c8e 100644
--- a/shell/core/src/main/java/org/apache/karaf/shell/support/ShellUtil.java
+++ b/shell/core/src/main/java/org/apache/karaf/shell/support/ShellUtil.java
@@ -183,8 +183,9 @@ public class ShellUtil {
session.getConsole().println(str);
}
session.getConsole().flush();
- } catch (Exception ignore) {
- // ignore
+ } catch (Throwable ignore) {
+ // ignore (catch Throwable to handle LinkageError from JLine
classloader
+ // changes during bundle refresh, which would otherwise kill the
console thread)
}
}