Problematic implementation of java.io.DataInputStream ?

Michael Koch konqueror@gmx.de
Mon May 19 18:37:00 GMT 2003


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi list,


the class java.io.DataInputStream uses a little buffer called "buf" to 
make primitive read calls more efficient.

The problem is that when two different threads call methods using this 
buffer the buffer may contain wrong data when one thread is 
interrupted between filling of the buffer and conversion of the 
primitive data type.

Example code:

public final char readChar () throws IOException
{
  readFully (buf, 0, 2);
  return convertToChar (buf);
}

Should we replace this code with not so much "optimized" code ? What 
do you think ?


Michael
- -- 
Homepage: http://www.worldforge.org/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)

iD8DBQE+yK+hWSOgCCdjSDsRAodmAKCB+5FLc8LooGl7Hpuok31yPfquYQCcCDrN
S44Hz0VIKwCEc5382KOP76s=
=zgck
-----END PGP SIGNATURE-----



More information about the Java mailing list