Object (final Object original) { // FormLayout may have been loaded with a different classloader, so we need to create a copy through serialization Object copy; try { BufferExposingByteArrayOutputStream baos = new BufferExposingByteArrayOutputStream(); try (ObjectOutputStream os = new ObjectOutputStream(baos)) { os.writeObject(original); } try (ObjectInputStream is = new ObjectInputStream(baos.toInputStream())) { copy = is.readObject(); } } catch (Exception e) { throw new RuntimeException(e); } return copy; }