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"
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"
- csr for
-
JDK-8269099 The documentation of the Scanner.hasNextLine is incorrect
-
- Closed
-