Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8268664

The documentation of the Scanner.hasNextLine is incorrect

    XMLWordPrintable

Details

    • b05
    • Not verified

    Description

      ADDITIONAL SYSTEM INFORMATION :
      Windows 10

      A DESCRIPTION OF THE PROBLEM :
      The current description: "Returns true if and only if this scanner has another line of input" is incorrect. To return true it is enough that the input of a scanner contains any additional characters, it doesn't have to be a new line character.

      See: https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/Scanner.html#hasNextLine()

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      import java.util.Scanner;

      public class Temp {
      public static void main(String[] args) {
      Scanner sc = new Scanner("a b");
      sc.next();
      System.out.println(sc.hasNextLine());
      }
      }

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      After executing sc.next() the scanner has no lines in the input other than the current line. hasNextLine() returns "true if and only if this scanner has another line of input". So according to the documentation the hasNextLine() should return false.
      ACTUAL -
      the code prints "true"

      Attachments

        Issue Links

          Activity

            People

              igraves Ian Graves
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: