- private static final class Proxy implements Externalizable {
- private static final long serialVersionUID = 1L;
-
- private CommitTransactionPayload payload;
-
- // checkstyle flags the public modifier as redundant which really doesn't make sense since it clearly isn't
- // redundant. It is explicitly needed for Java serialization to be able to create instances via reflection.
- @SuppressWarnings("checkstyle:RedundantModifier")
- public Proxy() {
- // For Externalizable
- }
-
- Proxy(final CommitTransactionPayload payload) {
- this.payload = requireNonNull(payload);
- }
-
- @Override
- public void writeExternal(final ObjectOutput out) throws IOException {
- out.writeInt(payload.size());
- payload.writeBytes(out);
- }
-
- @Override
- public void readExternal(final ObjectInput in) throws IOException {
- final int length = in.readInt();
- if (length < 0) {
- throw new StreamCorruptedException("Invalid payload length " + length);
- } else if (length < MAX_ARRAY_SIZE) {
- final byte[] serialized = new byte[length];
- in.readFully(serialized);
- payload = new Simple(serialized);
- } else {
- payload = new Chunked(ChunkedByteArray.readFrom(in, length, MAX_ARRAY_SIZE));
- }
- }
+ // Exists to break initialization dependency between CommitTransactionPayload/Simple/Proxy
+ private static final class ProxySizeHolder {
+ static final int PROXY_SIZE = SerializationUtils.serialize(new CT(new Simple(new byte[0]))).length;