-
Bug
-
Resolution: Cannot Reproduce
-
P4
-
None
-
1.0.2
-
sparc
-
solaris_2.5
Java language specification does not say that
java.io.DataOutputStream.writeXXX() does not check internal counter overflow
____ The Java Language Specification Version 1.0 ____
22.21.3 public void write(int b) throws IOException
The byte for this operation ... is written
to the contained output stream. If no exception is thrown, the counter
written is incremented by 1.
Implements the write method of OutputStream (§22.15.1).
_______________________Example ______________________________________
import java.io.*;
public class NewDataOutputStream extends DataOutputStream{
public static void main( String argv[] ) {
NewDataOutputStream d_out;
d_out = new NewDataOutputStream(System.out); // Create DataOutputStream object
System.out.println("Some Java-application wrote "+Integer.toString(d_out.size())+" bytes after hard-working.");
try {
d_out.writeByte(1); // Write "extra" byte
System.out.println("One additional byte..");
} catch (Exception e)
{ System.out.println("Ok. Some exception:"+e);
return;}
if (d_out.size()<0) // Check
{ System.out.println("Overflow , but no any exception thrown. Internal counter equals to "+Integer.toString(d_out.size()));
return;
}
System.out.println("No exceptions.No overflows.");
}
public NewDataOutputStream(OutputStream out) {
super(out);
written=Integer.MAX_VALUE; //Initialize internal counter with
// maximum value.
// Emulate that Integer.MAX_VALUE bytes
// been written.
}
public void write(int b) throws IOException {
// It does nothing in order to avoid real writing to enywhere.
}
public void close() throws IOException {
}
}
_____________________Output_________________________________________
Some Java-application wrote 2147483647 bytes after hard-working.
One additional byte..
Overflow , but no any exception thrown. Internal counter equals to -2147483648
____________________________________________________________________
java.io.DataOutputStream.writeXXX() does not check internal counter overflow
____ The Java Language Specification Version 1.0 ____
22.21.3 public void write(int b) throws IOException
The byte for this operation ... is written
to the contained output stream. If no exception is thrown, the counter
written is incremented by 1.
Implements the write method of OutputStream (§22.15.1).
_______________________Example ______________________________________
import java.io.*;
public class NewDataOutputStream extends DataOutputStream{
public static void main( String argv[] ) {
NewDataOutputStream d_out;
d_out = new NewDataOutputStream(System.out); // Create DataOutputStream object
System.out.println("Some Java-application wrote "+Integer.toString(d_out.size())+" bytes after hard-working.");
try {
d_out.writeByte(1); // Write "extra" byte
System.out.println("One additional byte..");
} catch (Exception e)
{ System.out.println("Ok. Some exception:"+e);
return;}
if (d_out.size()<0) // Check
{ System.out.println("Overflow , but no any exception thrown. Internal counter equals to "+Integer.toString(d_out.size()));
return;
}
System.out.println("No exceptions.No overflows.");
}
public NewDataOutputStream(OutputStream out) {
super(out);
written=Integer.MAX_VALUE; //Initialize internal counter with
// maximum value.
// Emulate that Integer.MAX_VALUE bytes
// been written.
}
public void write(int b) throws IOException {
// It does nothing in order to avoid real writing to enywhere.
}
public void close() throws IOException {
}
}
_____________________Output_________________________________________
Some Java-application wrote 2147483647 bytes after hard-working.
One additional byte..
Overflow , but no any exception thrown. Internal counter equals to -2147483648
____________________________________________________________________