Skip to content

Commit

Permalink
Return early from LineReaderImpl.doList if no possibilities or rows (f…
Browse files Browse the repository at this point in the history
…ixes #941) (#942)

* Fix StackOverflowError in detached Docker container (fixes #941)

When running inside a detached Docker container, calling LineReaderImpl.redisplay
resulted in a StackOverflowError. The reason for this is that redisplay eventually
calls doList, which again calls redisplay because the size.getRows() is 0.

* Add a unit test

---------

Co-authored-by: Kay Werndli <kay@spinque.com>
Co-authored-by: Guillaume Nodet <gnodet@gmail.com>
  • Loading branch information
3 people committed Apr 17, 2024
1 parent cfee77c commit 643b859
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5006,10 +5006,14 @@ protected boolean doList(
PostResult postResult = computePost(possible, null, null, completed);
int lines = postResult.lines;
int listMax = getInt(LIST_MAX, DEFAULT_LIST_MAX);
if (listMax > 0 && possible.size() >= listMax || lines >= size.getRows() - promptLines) {
int possibleSize = possible.size();
if (possibleSize == 0 || size.getRows() == 0) {
return false;
}
if (listMax > 0 && possibleSize >= listMax || lines >= size.getRows() - promptLines) {
if (!forSuggestion) {
// prompt
post = () -> new AttributedString(getAppName() + ": do you wish to see all " + possible.size()
post = () -> new AttributedString(getAppName() + ": do you wish to see all " + possibleSize
+ " possibilities (" + lines + " lines)?");
redisplay(true);
int c = readCharacter();
Expand Down
13 changes: 12 additions & 1 deletion reader/src/test/java/org/jline/reader/impl/CompletionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,18 @@ public void testDumbTerminalNoSizeComplete() {
reader.setCompleter(new StringsCompleter(
Arrays.asList("ae_helloWorld", "ad_helloWorld", "ac_helloWorld", "ab_helloWorld", "aa_helloWorld")));

assertLine("a", new TestBuffer("a\t\n\n"));
assertLine("a", new TestBuffer("a\t\n"));
}

@Test
public void testTerminalNoSizeComplete() {
terminal.setSize(new Size());
reader.doAutosuggestion = true;
reader.autosuggestion = LineReader.SuggestionType.COMPLETER;
reader.setCompleter(new StringsCompleter(
Arrays.asList("ae_helloWorld", "ad_helloWorld", "ac_helloWorld", "ab_helloWorld", "aa_helloWorld")));

assertLine("a", new TestBuffer("a\t\n"));
}

@Test
Expand Down

0 comments on commit 643b859

Please sign in to comment.