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

jbonofre pushed a commit to branch karaf-4.4.x
in repository https://gitbox.apache.org/repos/asf/karaf.git


The following commit(s) were added to refs/heads/karaf-4.4.x by this push:
     new 1a18b0e447 fix(shell): prevent LinkageError from killing the local 
console thread (#2316)
1a18b0e447 is described below

commit 1a18b0e44717e868dc73835392d705c5426a4c30
Author: JB Onofré <[email protected]>
AuthorDate: Sat Mar 14 12:06:04 2026 +0100

    fix(shell): prevent LinkageError from killing the local console thread 
(#2316)
    
    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)
         }
     }
 

Reply via email to