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

Change in java.util.Scanner.findInLine(".") behavior

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P3 P3
    • None
    • 6
    • core-libs
    • None
    • generic
    • generic

      Reference this forum posting:

      http://forums.java.net/jive/thread.jspa?threadID=16058&tstart=0


      If I compile and execute the following program FROM THE WINDOWS COMMAND LINE, I get different behavior under Java 6 than I did under Java 5. (With Java 6, I get a NullPointerException; with Java 5, I didn't.)

      import java.util.Scanner;

      public class TestScan {

          public static void main(String args[]) {
      Scanner keyboard = new Scanner(System.in);

      System.out.print("Number: ");
      int i = keyboard.nextInt();
      System.out.print("char: ");
      char c = keyboard.findInLine(".").charAt(0);
          }
      }
      Teasing apart the submitted test case shows that java.util.Scanner.findInLine(".") is returning null where it returned a String in earlier releases:

      import java.util.Scanner;

      public class TestScan {

          public static void main(String args[]) {
      Scanner keyboard = new Scanner(System.in);

      System.out.print("Number: ");
      int i = keyboard.nextInt();
      System.out.print("char: ");
      String s = keyboard.findInLine(".");
      if (s != null) {
      char c = s.charAt(0);
      System.out.println("c is: " + c);
      } else {
      System.out.println("s is null.");
      }
          }
      }

      % java -showversion TestScan
      java version "1.6.0-ea"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.6.0-ea-b45)
      Java HotSpot(TM) Client VM (build 1.6.0-ea-b45, mixed mode)

      Number: 8
      char: s is null.

            sherman Xueming Shen
            tbell Tim Bell
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: