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

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3
    • Resolution: Duplicate
    • Affects Version/s: 1.1
    • Fix Version/s: None
    • Component/s: core-libs
    • Labels:
      None
    • Subcomponent:
    • CPU:
      x86, sparc
    • OS:
      solaris_2.5, windows_95

      Description



      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();
        }
      }


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

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: