From 3fa0adf98bebbb72dd2e7fec39d091a0644b43f2 Mon Sep 17 00:00:00 2001 From: mkrueger92 <7305571+mkrueger92@users.noreply.github.com> Date: Thu, 10 Jan 2019 10:23:56 +0100 Subject: [PATCH] Clear internal history in case of currupted histroy file The expected behaviour when loading of a history files fails is that the issue is logged but the reader is usable. The current behaviour results in a IllegalArgumentException (from the addHistoryLine(Path, String) function) which is never caught. This results is a different behaviour than for example the file permission does not allow to read the file. As a consequence in Karaf the session is not useable because of returned "null" at some point which is interpreted as session end. This commit introduces a fix which catches the IllegalArgumentException and keeps the reader usable without history information. Also this makes the behaviour consistent. --- .../java/org/jline/reader/impl/history/DefaultHistory.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/reader/src/main/java/org/jline/reader/impl/history/DefaultHistory.java b/reader/src/main/java/org/jline/reader/impl/history/DefaultHistory.java index c131244ae..bd4ceaa1e 100644 --- a/reader/src/main/java/org/jline/reader/impl/history/DefaultHistory.java +++ b/reader/src/main/java/org/jline/reader/impl/history/DefaultHistory.java @@ -69,7 +69,7 @@ public void attach(LineReader reader) { try { load(); } - catch (IOException e) { + catch (IllegalArgumentException | IOException e) { Log.warn("Failed to load history", e); } } @@ -90,7 +90,7 @@ public void load() throws IOException { maybeResize(); } } - } catch (IOException e) { + } catch (IllegalArgumentException | IOException e) { Log.debug("Failed to load history; clearing", e); internalClear(); throw e;