java.io/301: StreamTokenizer doesn't handle escaped newline

osk@hem.passagen.se osk@hem.passagen.se
Fri Aug 4 09:20:00 GMT 2000


>Number:         301
>Category:       java.io
>Synopsis:       StreamTokenizer doesn't handle escaped newline
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    tromey
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Aug 04 09:20:00 PDT 2000
>Closed-Date:
>Last-Modified:
>Originator:     Oskar Liljeblad
>Release:        unknown-1.0
>Organization:
>Environment:
libgcj-snapshot-2000-07-24
>Description:
The StreamTokenizer of Sun's JDK supports escaping of
a newline (CR/LF) by putting a backslash in front of it.
This is not supported in the GCJ or Classpath
StreamTokenizer class.

The program below gives different output for GCJ and
Sun's JDK.

I did some testing and it seems that only the first
newline character is escaped, even if the stream
contains <CR><LF> newlines.
>How-To-Repeat:
import java.io.*;
class Test {
  public static void main(String[] args) throws IOException {
    StringReader r = new StringReader("\"foo\\\nbar\" after");
    StreamTokenizer st = new StreamTokenizer(r);
    System.out.println(st.nextToken()+": "+st.sval.length()+" >"+st.sval+"<");
    System.out.println(st.nextToken()+": "+st.sval.length()+" >"+st.sval+"<");
  }
}  
>Fix:
--- libjava/java/io/StreamTokenizer.java.old    Fri Aug  4 18:08:33 2000
+++ libjava/java/io/StreamTokenizer.java        Fri Aug  4 18:04:49 2000
@@ -365,6 +365,10 @@
                    break;
                  case 'v':     ch = 0xB;
                    break;
+                 case '\n':    ch = '\n';
+                   break;
+                 case '\r':    ch = '\r';
+                   break;
                  case '\"':
                  case '\'':
                  case '\\':
>Release-Note:
>Audit-Trail:
>Unformatted:


More information about the Java-prs mailing list