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 1b1f0a0c8..bbccecb3e 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 @@ -344,7 +344,11 @@ private String format(Entry entry) { } public String get(final int index) { - return items.get(index - offset).line(); + int idx = index - offset; + if (idx >= items.size() || idx < 0) { + throw new IllegalArgumentException("IndexOutOfBounds: Index:" + idx +", Size:" + items.size()); + } + return items.get(idx).line(); } @Override