-
Bug
-
Resolution: Duplicate
-
P4
-
None
-
1.4.2
-
x86
-
linux
Name: gm110360 Date: 10/14/2003
FULL PRODUCT VERSION :
java version "1.4.2_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_01-b06)
Java HotSpot(TM) Client VM (build 1.4.2_01-b06, mixed mode)
FULL OS VERSION :
Linux spike 2.4.20-8 #1 Thu Mar 13 17:54:28 EST 2003 i686 i686 i386 GNU/Linux
A DESCRIPTION OF THE PROBLEM :
OutputStreamWriter fails to write character value=55297 or higher; root cause is
java.lang.Error
at sun.nio.cs.StreamEncoder$CharsetSE.flushLeftoverChar(StreamEncoder.java:361)
at sun.nio.cs.StreamEncoder$CharsetSE.implWrite(StreamEncoder.java:381)
at sun.nio.cs.StreamEncoder.write(StreamEncoder.java:136)
at sun.nio.cs.StreamEncoder.write(StreamEncoder.java:124)
at java.io.OutputStreamWriter.write(OutputStreamWriter.java:178)
at utf_er.compareAll(utf_er.java:50)
at utf_er.main(utf_er.java:8)
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
run the enclosed code with the command:
java utf_er
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
debugging lines like
wrote 54000
read 54000
ACTUAL -
java.lang.Error thrown by sun.nio.cs.StreamEncoder$CharsetSE.flushLeftoverChar
ERROR MESSAGES/STACK TRACES THAT OCCUR :
Error on character 55297
java.lang.Error
at sun.nio.cs.StreamEncoder$CharsetSE.flushLeftoverChar(StreamEncoder.java:361)
at sun.nio.cs.StreamEncoder$CharsetSE.implWrite(StreamEncoder.java:381)
at sun.nio.cs.StreamEncoder.write(StreamEncoder.java:136)
at sun.nio.cs.StreamEncoder.write(StreamEncoder.java:124)
at java.io.OutputStreamWriter.write(OutputStreamWriter.java:178)
at utf_er.compareAll(utf_er.java:50)
at utf_er.main(utf_er.java:8)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.io.*;
public class utf_er
{
public static void main(String [] args)
{
compareAll("UTF8", "UTF-16");
}
/**
* Compares two encodings over entire range
*
* @param enc1 first encoding
* @param enc2 second encoding
*/
private static void compareAll(final String enc1, final String enc2)
{
Writer out1 = null;
Writer out2 = null;
char ch = 0;
try
{
System.out.println("Comparing all values for " + enc1 +" to " + enc2);
PipedOutputStream pos1 = new PipedOutputStream();
final PipedInputStream pis1 = new PipedInputStream(pos1);
out1 = new OutputStreamWriter(pos1, enc1);
PipedOutputStream pos2 = new PipedOutputStream();
final PipedInputStream pis2 = new PipedInputStream(pos2);
out2 = new OutputStreamWriter(pos2, enc2);
new Thread(new Runnable()
{
public void run()
{
compare(pis1, enc1, pis2, enc2);
}
}).start();
for(ch = 50000 + Character.MIN_VALUE; ch <= Character.MAX_VALUE; ch++)
{
if(ch % 1000 == 0)
{
System.err.println(" wrote " + (int)ch);
}
out1.write(ch);
out2.write(ch);
out1.flush();
out2.flush();
}
}
catch(Throwable e)
{
System.err.println();
System.err.println("Error on character " + (int)ch);
while(e != null)
{
e.printStackTrace();
e = e.getCause();
}
}
finally
{
try { out1.close(); } catch(IOException e) {}
try { out2.close(); } catch(IOException e) {}
}
}
/**
* Compare two streams.
*
* @param in1 first stream
* @param enc1 encoding for first stream
* @param in2 second stream
* @param enc2 encoding for second stream
*/
private static void compare(InputStream ins1, String enc1, InputStream ins2, String enc2)
{
Reader in1 = null;
Reader in2 = null;
done:
try
{
in1 = new BufferedReader(
new InputStreamReader(ins1, enc1));
in2 = new BufferedReader(
new InputStreamReader(ins2, enc2));
int ch1 = in1.read();
int ch2 = in2.read();
while(ch1 != -1 && ch2 != -1)
{
if(ch1 % 1000 == 0)
{
System.err.println("\tread " + ch1);
}
if(ch1 != ch2)
{
System.out.println(" differ");
break done;
}
ch1 = in1.read();
ch2 = in2.read();
}
if(ch1 != -1)
{
System.out.println(" first is longer.");
}
if(ch2 != -1)
{
System.out.print("second is longer.");
}
}
catch(IOException e)
{
e.printStackTrace();
}
finally
{
try { in1.close(); } catch(IOException e) {}
try { in2.close(); } catch(IOException e) {}
}
}
}
---------- END SOURCE ----------
(Incident Review ID: 215522)
======================================================================
FULL PRODUCT VERSION :
java version "1.4.2_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_01-b06)
Java HotSpot(TM) Client VM (build 1.4.2_01-b06, mixed mode)
FULL OS VERSION :
Linux spike 2.4.20-8 #1 Thu Mar 13 17:54:28 EST 2003 i686 i686 i386 GNU/Linux
A DESCRIPTION OF THE PROBLEM :
OutputStreamWriter fails to write character value=55297 or higher; root cause is
java.lang.Error
at sun.nio.cs.StreamEncoder$CharsetSE.flushLeftoverChar(StreamEncoder.java:361)
at sun.nio.cs.StreamEncoder$CharsetSE.implWrite(StreamEncoder.java:381)
at sun.nio.cs.StreamEncoder.write(StreamEncoder.java:136)
at sun.nio.cs.StreamEncoder.write(StreamEncoder.java:124)
at java.io.OutputStreamWriter.write(OutputStreamWriter.java:178)
at utf_er.compareAll(utf_er.java:50)
at utf_er.main(utf_er.java:8)
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
run the enclosed code with the command:
java utf_er
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
debugging lines like
wrote 54000
read 54000
ACTUAL -
java.lang.Error thrown by sun.nio.cs.StreamEncoder$CharsetSE.flushLeftoverChar
ERROR MESSAGES/STACK TRACES THAT OCCUR :
Error on character 55297
java.lang.Error
at sun.nio.cs.StreamEncoder$CharsetSE.flushLeftoverChar(StreamEncoder.java:361)
at sun.nio.cs.StreamEncoder$CharsetSE.implWrite(StreamEncoder.java:381)
at sun.nio.cs.StreamEncoder.write(StreamEncoder.java:136)
at sun.nio.cs.StreamEncoder.write(StreamEncoder.java:124)
at java.io.OutputStreamWriter.write(OutputStreamWriter.java:178)
at utf_er.compareAll(utf_er.java:50)
at utf_er.main(utf_er.java:8)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.io.*;
public class utf_er
{
public static void main(String [] args)
{
compareAll("UTF8", "UTF-16");
}
/**
* Compares two encodings over entire range
*
* @param enc1 first encoding
* @param enc2 second encoding
*/
private static void compareAll(final String enc1, final String enc2)
{
Writer out1 = null;
Writer out2 = null;
char ch = 0;
try
{
System.out.println("Comparing all values for " + enc1 +" to " + enc2);
PipedOutputStream pos1 = new PipedOutputStream();
final PipedInputStream pis1 = new PipedInputStream(pos1);
out1 = new OutputStreamWriter(pos1, enc1);
PipedOutputStream pos2 = new PipedOutputStream();
final PipedInputStream pis2 = new PipedInputStream(pos2);
out2 = new OutputStreamWriter(pos2, enc2);
new Thread(new Runnable()
{
public void run()
{
compare(pis1, enc1, pis2, enc2);
}
}).start();
for(ch = 50000 + Character.MIN_VALUE; ch <= Character.MAX_VALUE; ch++)
{
if(ch % 1000 == 0)
{
System.err.println(" wrote " + (int)ch);
}
out1.write(ch);
out2.write(ch);
out1.flush();
out2.flush();
}
}
catch(Throwable e)
{
System.err.println();
System.err.println("Error on character " + (int)ch);
while(e != null)
{
e.printStackTrace();
e = e.getCause();
}
}
finally
{
try { out1.close(); } catch(IOException e) {}
try { out2.close(); } catch(IOException e) {}
}
}
/**
* Compare two streams.
*
* @param in1 first stream
* @param enc1 encoding for first stream
* @param in2 second stream
* @param enc2 encoding for second stream
*/
private static void compare(InputStream ins1, String enc1, InputStream ins2, String enc2)
{
Reader in1 = null;
Reader in2 = null;
done:
try
{
in1 = new BufferedReader(
new InputStreamReader(ins1, enc1));
in2 = new BufferedReader(
new InputStreamReader(ins2, enc2));
int ch1 = in1.read();
int ch2 = in2.read();
while(ch1 != -1 && ch2 != -1)
{
if(ch1 % 1000 == 0)
{
System.err.println("\tread " + ch1);
}
if(ch1 != ch2)
{
System.out.println(" differ");
break done;
}
ch1 = in1.read();
ch2 = in2.read();
}
if(ch1 != -1)
{
System.out.println(" first is longer.");
}
if(ch2 != -1)
{
System.out.print("second is longer.");
}
}
catch(IOException e)
{
e.printStackTrace();
}
finally
{
try { in1.close(); } catch(IOException e) {}
try { in2.close(); } catch(IOException e) {}
}
}
}
---------- END SOURCE ----------
(Incident Review ID: 215522)
======================================================================
- duplicates
-
JDK-4912159 (cs) Stream encoder handles split malformed surrogates incorrectly
-
- Closed
-