Description: | When an ObjectOutputStream instance wraps an underlying ByteArrayOutputStream instance,
it is recommended to flush or close the ObjectOutputStream before invoking the underlying instances's toByteArray().
Although in these cases this is not strictly necessary because the
writeObject method is invoked right before toByteArray, and writeObject
internally calls flush/drain. However, it is a good practice to call
flush/close explicitly as mentioned for example here.
This pull request flips the order of close and toByteArray methods. |
Code with Misuse: |
class TestMonthDay_Basics {
//-----------------------------------------------------------------------
public void testSerialization() throws Exception {
MonthDay test = new MonthDay(5, 6, COPTIC_PARIS);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(test);
byte[] bytes = baos.toByteArray();
oos.close();
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
ObjectInputStream ois = new ObjectInputStream(bais);
MonthDay result = (MonthDay) ois.readObject();
ois.close();
assertEquals(test, result);
assertTrue(Arrays.equals(test.getValues(), result.getValues()));
assertTrue(Arrays.equals(test.getFields(), result.getFields()));
assertEquals(test.getChronology(), result.getChronology());
}
}
|