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

java.io.StreamTokenizer.nextToken() doesn't work when chr(32) has its white-spac

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • None
    • 1.1
    • core-libs
    • None
    • x86, sparc
    • solaris_2.5, windows_95



      Name: el35337 Date: 01/09/97



      /*
      Jonathan Cheyer
      ###@###.###
      18 Dec 1996

      This program demonstrates that when ascii chr(32) has its white-space
      attribute removed, nextToken() does not work correctly.

      Apparently, chr(32) was hard-coded into the nextToken() method to be
      used as a character that is "guaranteed" to have the white-space
      attribute set on.

      This program should wait for input from stdin and return the first
      token.
      This works unless chr(32) has its white-space attribute removed. In
      that
      case, nextToken() returns an initial space instead of reading the next
      token.

      This isn't the expected behavior as described in:

      Java Language Specification
      Gosling, Joy, Steele
      Version 1.0
      Chapter 22.14: Class java.io.StreamTokenizer
      http://www.javasoft.com/doc/language_specification/javaio.doc.html
      */

      import java.io.StreamTokenizer;
      import java.io.IOException;

      public class test {

        public test() {

          int t;
          StreamTokenizer st = new StreamTokenizer(System.in);

          /* Uncommenting the line below causes nextToken() to break */
      // st.ordinaryChar(32);

          try {
            System.out.println("ttype before calling nextToken: " + st.ttype);
            t = st.nextToken();
            System.out.println("ttype after calling nextToken: " + st.ttype);
            if (t == StreamTokenizer.TT_WORD){
              System.out.print("sval[0] = chr(" + (int) st.sval.charAt(0));
              System.out.println("), sval = " + "'" + st.sval + "'");
            }
          }
          catch (IOException e) {
            System.out.println("error");
            System.exit(-1);
          }
        }

        public static void main(String argv[]) {
          test temp = new test();
        }
      }


      ======================================================================

            apalanissunw Anand Palaniswamy (Inactive)
            elarsen Erik Larsen (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: