-
Bug
-
Resolution: Fixed
-
P3
-
6
-
b57
-
generic
-
windows_xp
-
Verified
The methods of Console class
java.io.Console.readLine()
java.io.Console.readLine(String fmt,Object ...args)
java.io.readPassword()
java.io.readPassword(String fmt,Object ...args)
throws java.lang.ArrayIndexOutOfBoundsException when the input stream exceeds 1024 characters.Since the readLine() method reads a line until line termination, and line bound is considered to be any one of line feed,carriage return,and carriage return followed immediately by a line feed, It should read more than 1024 characters if the user wants to give a line containing more than 1024 characters.
Please see the following version,code and result.
Tried in Windows XP Professional
<version>
C:\work>java -version
java version "1.6.0-auto"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.6.0-auto-277)
Java HotSpot(TM) Client VM (build 1.6.0-ea-b55, mixed mode)
</version>
<code>
import java.io.Console;
import static java.lang.System.out;
class TestCon {
public static void main(String ...args) {
Console con = System.console();
if (con!=null){
String sg =con.readLine();
out.println("string read is "+sg);
}
}
}
</code>
result when run
<result>
C:\work>java TestCon
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1024
at java.io.Console$LineReader.read(Console.java:435)
at java.io.Console.readline(Console.java:346)
at java.io.Console.readLine(Console.java:232)
at java.io.Console.readLine(Console.java:254)
at TestCon.main(TestCon.java:14)
</result>
java.io.Console.readLine()
java.io.Console.readLine(String fmt,Object ...args)
java.io.readPassword()
java.io.readPassword(String fmt,Object ...args)
throws java.lang.ArrayIndexOutOfBoundsException when the input stream exceeds 1024 characters.Since the readLine() method reads a line until line termination, and line bound is considered to be any one of line feed,carriage return,and carriage return followed immediately by a line feed, It should read more than 1024 characters if the user wants to give a line containing more than 1024 characters.
Please see the following version,code and result.
Tried in Windows XP Professional
<version>
C:\work>java -version
java version "1.6.0-auto"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.6.0-auto-277)
Java HotSpot(TM) Client VM (build 1.6.0-ea-b55, mixed mode)
</version>
<code>
import java.io.Console;
import static java.lang.System.out;
class TestCon {
public static void main(String ...args) {
Console con = System.console();
if (con!=null){
String sg =con.readLine();
out.println("string read is "+sg);
}
}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aaaaaaa
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1024
at java.io.Console$LineReader.read(Console.java:435)
at java.io.Console.readline(Console.java:346)
at java.io.Console.readLine(Console.java:232)
at java.io.Console.readLine(Console.java:254)
at TestCon.main(TestCon.java:14)
</result>