bug-classpath
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug classpath/39197] New: java.util.Scanner(InputStream) should not fil


From: jre21 at cwru dot edu
Subject: [Bug classpath/39197] New: java.util.Scanner(InputStream) should not fill buffer
Date: 15 Feb 2009 19:33:19 -0000

When calling Scanner() with an InputStream as an argument, the program
waits for input in order to fill the buffer.  Then when one of the
next*() methods is called, the program returns the input that it
received when the Scanner() was constructed.

The error can be reproduced by compiling and running the following
program.

  import java.util.Scanner;

  public class TestScanner {
    public static void main(String argv[]) {
      String foo;
      System.out.println("marker 0");
      Scanner input0 = new Scanner(System.in);
      System.out.println("Enter a word or phrase: ");
      foo = input0.nextLine();
      System.out.printf("You entered: %s\n", foo);
    }
  }

expected output (lines typed to the console are preceeded with a '>'
character):

  marker 0
  Enter a word or phrase: 
  > foo bar
  You entered: foo bar

actual output:

  marker 0
  > foo bar
  Enter a word or phrase: 
  > baz foobar
  You entered: foo bar

How to Fix:

In java/util/Scanner.java, the relevant constructor is:

  public Scanner (final InputStream source, final String charsetName)
  {
    this.bIS = (new BufferedInputStream (source));
    this.charsetName = charsetName;
    myFillBuffer ();
  }

Simply remove the 'myFillBuffer ();' line to restore the behavior
described by the java API.


-- 
           Summary: java.util.Scanner(InputStream) should not fill buffer
           Product: classpath
           Version: 0.98
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: classpath
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: jre21 at cwru dot edu
 GCC build triplet: x86_64-unknown-linux-gnu
  GCC host triplet: x86_64-unknown-linux-gnu
GCC target triplet: x86_64-unknown-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39197





reply via email to

[Prev in Thread] Current Thread [Next in Thread]