Skip to content

Commit

Permalink
fix(ui/cli): close scanner after usage
Browse files Browse the repository at this point in the history
  • Loading branch information
thetric committed Jun 11, 2017
1 parent d58c121 commit 5082a86
Showing 1 changed file with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ final class SystemEnvironmentAwareConsoleService implements ConsoleService {
}

print "$prompt: "
final Scanner scanner = new Scanner(System.in)
return scanner.nextLine()
return readNextLine()
}

/**
Expand All @@ -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()
}
}
}

0 comments on commit 5082a86

Please sign in to comment.