Name: rmT116609 Date: 09/02/2004
A DESCRIPTION OF THE PROBLEM :
There is an incoherence in the class DataOutputStream about the thread-safe status of the class :
The 2 following functions of the class java.io.DataOutputStream are doing about the same things, but one of them is thread-safe and the other one is not
public synchronized void write(int b) throws IOException {
out.write(b);
incCount(1);
}
public final void writeBoolean(boolean v) throws IOException {
out.write(v ? 1 : 0);
incCount(1);
}
The incCount() method copied below is CLEARLY NOT thread-safe :
private void incCount(int value) {
int temp = written + value;
if (temp < 0) {
temp = Integer.MAX_VALUE;
}
written = temp;
}
Now, 2 possibilities :
- You assume that the class shouldn't be thread-safe, and then you don't need the synchronizations on none of the methods.
- You assume that the class should be thread-safe, and then all the write{Boolean, short, ...}() functions should be synchonized and there is actually a bug because they aren't.
REPRODUCIBILITY :
This bug can be reproduced always.
(Incident Review ID: 301238)
======================================================================
A DESCRIPTION OF THE PROBLEM :
There is an incoherence in the class DataOutputStream about the thread-safe status of the class :
The 2 following functions of the class java.io.DataOutputStream are doing about the same things, but one of them is thread-safe and the other one is not
public synchronized void write(int b) throws IOException {
out.write(b);
incCount(1);
}
public final void writeBoolean(boolean v) throws IOException {
out.write(v ? 1 : 0);
incCount(1);
}
The incCount() method copied below is CLEARLY NOT thread-safe :
private void incCount(int value) {
int temp = written + value;
if (temp < 0) {
temp = Integer.MAX_VALUE;
}
written = temp;
}
Now, 2 possibilities :
- You assume that the class shouldn't be thread-safe, and then you don't need the synchronizations on none of the methods.
- You assume that the class should be thread-safe, and then all the write{Boolean, short, ...}() functions should be synchonized and there is actually a bug because they aren't.
REPRODUCIBILITY :
This bug can be reproduced always.
(Incident Review ID: 301238)
======================================================================