This code demonstrates that ObjectOutputStream may not write the current contents of an object.
We initialize an array to [null] and write it to an output stream. Then we change the value of an array element to a non-null value, and write it again. This program demonstrates that [null] is again written, instead of the current contents of the array.
Not a bug, but documented behavior. ObjectOutputStream keeps track of every object that it writes. When you write an object a second time, a reference to that object is written instead of a new copy of that object's data. This is how circular references are dealt with. So once you write your array, writing it again wwill just cause a reference to the earlier copy to be written; the current state won't be inspected.
You can call reset() on an ObjectOutputStream to flush the cache of old object references and start anew -- but note that if you write an object, change it, call reset(), and write it again, deserialization will give you two separate objects.