diff options
-rw-r--r-- | src/jvm14-library/scala/Console.scala | 11 | ||||
-rw-r--r-- | src/library/scala/Console.scala | 10 |
2 files changed, 15 insertions, 6 deletions
diff --git a/src/jvm14-library/scala/Console.scala b/src/jvm14-library/scala/Console.scala index fe29150caa..0562ec8de1 100644 --- a/src/jvm14-library/scala/Console.scala +++ b/src/jvm14-library/scala/Console.scala @@ -187,11 +187,16 @@ object Console { else MessageFormat.format(text, textParams(args)) ) - /** Read a full line from the terminal. + /** Read a full line from the terminal. Throws EOFException if the end of the + * input stream has been reached. * - * @return the string read from the terminal. + * @return the string read from the terminal. + * @throws java.io.EOFException */ - def readLine(): String = in.readLine() + def readLine(): String = { + val s = in.readLine() + if (s == null) throw new java.io.EOFException("Console has reached end of input") else s + } /** Print a formatted text and read a full line from the terminal * diff --git a/src/library/scala/Console.scala b/src/library/scala/Console.scala index 519fab403d..204d7d7c35 100644 --- a/src/library/scala/Console.scala +++ b/src/library/scala/Console.scala @@ -186,12 +186,16 @@ object Console { out.printf(text, args.asInstanceOf[scala.runtime.BoxedObjectArray]. unbox(args.getClass).asInstanceOf[Array[Object]]) - /** Read a full line from the terminal. Returns null if the end of the + /** Read a full line from the terminal. Throws EOFException if the end of the * input stream has been reached. * - * @return the string read from the terminal. + * @return the string read from the terminal. + * @throws java.io.EOFException */ - def readLine(): String = in.readLine() + def readLine(): String = { + val s = in.readLine() + if (s == null) throw new java.io.EOFException("Console has reached end of input") else s + } /** Print a formatted text and read a full line from the terminal. * Returns null if the end of the input stream has been reached. |