Skip to content

Commit

Permalink
NPE when building LineReader without explicit terminal, fixes #110
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet committed Apr 11, 2017
1 parent ec945e1 commit 70f1c96
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
11 changes: 11 additions & 0 deletions reader/src/main/java/org/jline/reader/LineReaderBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@
*/
package org.jline.reader;

import java.io.IOError;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import org.jline.reader.impl.LineReaderImpl;
import org.jline.reader.impl.history.DefaultHistory;
import org.jline.terminal.Terminal;
import org.jline.terminal.TerminalBuilder;

public final class LineReaderBuilder {

Expand Down Expand Up @@ -87,6 +90,14 @@ public LineReaderBuilder expander(Expander expander) {
}

public LineReader build() {
Terminal terminal = this.terminal;
if (terminal == null) {
try {
terminal = TerminalBuilder.terminal();
} catch (IOException e) {
throw new IOError(e);
}
}
LineReaderImpl reader = new LineReaderImpl(terminal, appName, variables);
if (history != null) {
reader.setHistory(history);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ public LineReaderImpl(Terminal terminal, String appName) throws IOException {
}

public LineReaderImpl(Terminal terminal, String appName, Map<String, Object> variables) {
Objects.requireNonNull(terminal);
Objects.requireNonNull(terminal, "terminal can not be null");
this.terminal = terminal;
if (appName == null) {
appName = "JLine";
Expand Down

0 comments on commit 70f1c96

Please sign in to comment.