From d9d2bbaca517299da222ea62484b148bab10411b Mon Sep 17 00:00:00 2001 From: DmitriyMX Date: Wed, 16 Dec 2015 14:45:32 +0300 Subject: [PATCH] hotfix: NullPointerException --- .../java/ru/dmitriymx/shell/CommandCompleter.java | 2 +- src/main/java/ru/dmitriymx/shell/Shell.java | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/main/java/ru/dmitriymx/shell/CommandCompleter.java b/src/main/java/ru/dmitriymx/shell/CommandCompleter.java index affff93..157dbe1 100644 --- a/src/main/java/ru/dmitriymx/shell/CommandCompleter.java +++ b/src/main/java/ru/dmitriymx/shell/CommandCompleter.java @@ -11,7 +11,7 @@ import java.util.List; * 2015 */ public class CommandCompleter implements Completer { - protected StringsCompleter stringsCompleter = new StringsCompleter(); + protected StringsCompleter stringsCompleter; @Override public int complete(String buffer, int cursor, List candidates) { diff --git a/src/main/java/ru/dmitriymx/shell/Shell.java b/src/main/java/ru/dmitriymx/shell/Shell.java index fa647de..19110c9 100644 --- a/src/main/java/ru/dmitriymx/shell/Shell.java +++ b/src/main/java/ru/dmitriymx/shell/Shell.java @@ -2,11 +2,14 @@ package ru.dmitriymx.shell; import jline.console.ConsoleReader; import jline.console.completer.ArgumentCompleter; +import jline.console.completer.StringsCompleter; import ru.dmitriymx.shell.commands.Command; import ru.dmitriymx.shell.commands.ExitCommand; import java.io.IOException; import java.io.PrintStream; +import java.util.HashMap; +import java.util.Map; /** * @author DmitriyMX @@ -23,6 +26,8 @@ public class Shell { private CommandCompleter commandCompleter; private Formatter formatter; protected boolean run = false; + private Map commandMap = new HashMap<>(); + private StringsCompleter stringsCompleter = new StringsCompleter(); public void start() throws IOException, InterruptedException { if (sysErr == null) overrideSysOutErr(); @@ -31,8 +36,10 @@ public class Shell { if (promt == null) promt = ":"; console.setPrompt(ConsoleReader.RESET_LINE + promt); console.addCompleter((commandCompleter = new CommandCompleter())); + commandCompleter.stringsCompleter = stringsCompleter; newErr.setConsoleReader(console); commandLoop = new CommandLoop(this); + commandLoop.commandMap = commandMap; if (!commandLoop.commandMap.containsKey("exit")) { addCommand(new ExitCommand()); @@ -62,8 +69,8 @@ public class Shell { public void addCommand(Command command) { command.setShell(this); String name = command.getName().toLowerCase(); - commandLoop.commandMap.put(name, command); - commandCompleter.stringsCompleter.getStrings().add(name); + commandMap.put(name, command); + stringsCompleter.getStrings().add(name); } public boolean isRunning() {