Skip to content

Commit 76c5bb3

Browse files
committed
Better comments / documentation.
1 parent c3252a2 commit 76c5bb3

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

lib/src/main/java/com/diffplug/spotless/FormatterStepSerializationRoundtrip.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,18 @@ protected FormatterFunc stateToFormatter(EqualityState equalityState) throws Exc
6565
}
6666

6767
private void writeObject(java.io.ObjectOutputStream out) throws IOException {
68-
if (initializer != null && roundtripStateInternal == null) {
69-
roundtripStateInternal = ThrowingEx.get(this::roundtripStateSupplier);
68+
if (initializer == null) {
69+
// then this instance was created by Gradle's ConfigurationCacheHackList and the following will hold true
70+
if (roundtripStateInternal == null && equalityStateInternal == null) {
71+
throw new IllegalStateException("If the initializer was null, then one of roundtripStateInternal or equalityStateInternal should be non-null, and neither was");
72+
}
73+
} else {
74+
// this was a normal instance, which means we need to encode to roundtripStateInternal (since the initializer might not be serializable)
75+
// and there's no reason to keep equalityStateInternal since we can always recompute it
76+
if (roundtripStateInternal == null) {
77+
roundtripStateInternal = ThrowingEx.get(this::roundtripStateSupplier);
78+
}
79+
equalityStateInternal = null;
7080
}
7181
out.defaultWriteObject();
7282
}

0 commit comments

Comments
 (0)