Skip to content

Commit 2be1291

Browse files
committed
JvmLocalCache should force state evaluation of any LazyForwardingEquality to give it a chance to null-out its initializing lambda.
Addresses #1194 (comment)
1 parent a0a96e3 commit 2be1291

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016 DiffPlug
2+
* Copyright 2016-2022 DiffPlug
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -111,4 +111,9 @@ static byte[] toBytes(Serializable obj) {
111111
}
112112
return byteOutput.toByteArray();
113113
}
114+
115+
/** Ensures that the lazy state has been evaluated. */
116+
public static void unlazy(LazyForwardingEquality<?> in) {
117+
in.state();
118+
}
114119
}

plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JvmLocalCache.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2021 DiffPlug
2+
* Copyright 2021-2022 DiffPlug
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -26,6 +26,7 @@
2626
import org.gradle.api.Task;
2727

2828
import com.diffplug.spotless.FileSignature;
29+
import com.diffplug.spotless.LazyForwardingEquality;
2930

3031
class JvmLocalCache {
3132
private static GradleException cacheIsStale() {
@@ -53,6 +54,11 @@ static class LiveCacheKeyImpl<T> implements LiveCache<T>, Serializable {
5354

5455
@Override
5556
public void set(T value) {
57+
if (value instanceof LazyForwardingEquality) {
58+
// whenever we cache an instance of LazyForwardingEquality, we want to make sure that we give it
59+
// a chance to null-out its initialization lambda (see https://github.com/diffplug/spotless/issues/1194#issuecomment-1120744842)
60+
LazyForwardingEquality.unlazy((LazyForwardingEquality<?>) value);
61+
}
5662
daemonState.put(internalKey, value);
5763
}
5864

0 commit comments

Comments
 (0)