'why does the ObjectOutputStream throw the invalid stream header 000000 error?

the method receives a stream of bytes and returns an object of type Data. Everything works fine without threads. But when using threads, the method causes the invalid stream header 00000 error.

public synchronized Data byteToData(byte[] bytes) throws IOException, ClassNotFoundException {
    ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes);
    ObjectInputStream objectInputStream = new ObjectInputStream(byteArrayInputStream);
    objectInputStream.close();
    byteArrayInputStream.close();
    return (Data) objectInputStream.readObject();
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source