public static void main(String[] args) throws Exception { for (int i = 0; i < 20; i++) { ByteArrayOutputStream bout = new ByteArrayOutputStream(); ObjectOutputStream oout = new ObjectOutputStream(bout); Item item = new Item(); oout.writeObject(item); oout.close(); ObjectInputStream oin = new ObjectInputStream(new ByteArrayInputStream(bout.toByteArray())); Item itemcopy = (Item) oin.readObject(); if (!item.equals(itemcopy)) { throw new Error(); } } }