From 5082a865518992f1f34575c1326c70ea07bd05b5 Mon Sep 17 00:00:00 2001 From: thetric Date: Sun, 11 Jun 2017 20:21:04 +0200 Subject: [PATCH] fix(ui/cli): close scanner after usage --- .../SystemEnvironmentAwareConsoleService.groovy | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/ui/cli/src/main/groovy/com/github/thetric/iliasdownloader/cli/console/SystemEnvironmentAwareConsoleService.groovy b/ui/cli/src/main/groovy/com/github/thetric/iliasdownloader/cli/console/SystemEnvironmentAwareConsoleService.groovy index dceda3b..ae35feb 100644 --- a/ui/cli/src/main/groovy/com/github/thetric/iliasdownloader/cli/console/SystemEnvironmentAwareConsoleService.groovy +++ b/ui/cli/src/main/groovy/com/github/thetric/iliasdownloader/cli/console/SystemEnvironmentAwareConsoleService.groovy @@ -19,8 +19,7 @@ final class SystemEnvironmentAwareConsoleService implements ConsoleService { } print "$prompt: " - final Scanner scanner = new Scanner(System.in) - return scanner.nextLine() + return readNextLine() } /** @@ -45,7 +44,15 @@ final class SystemEnvironmentAwareConsoleService implements ConsoleService { } log.warn('Password input in IDEs are _not_ supported') log.warn('FALLING BACK TO PLAIN TEXT MODE') - final Scanner s = new Scanner(System.in) - return s.nextLine() + return readNextLine() + } + + private String readNextLine() { + final Scanner scanner = new Scanner(System.in) + try { + return scanner.nextLine() + } finally { + scanner.close() + } } }