Skip to content

Commit

Permalink
JvmLocalCache should force state evaluation of any LazyForwardingEqua…
Browse files Browse the repository at this point in the history
…lity to give it a chance to null-out its initializing lambda.

Addresses #1194 (comment)
  • Loading branch information
nedtwigg committed May 9, 2022
1 parent a0a96e3 commit 2be1291
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016 DiffPlug
* Copyright 2016-2022 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -111,4 +111,9 @@ static byte[] toBytes(Serializable obj) {
}
return byteOutput.toByteArray();
}

/** Ensures that the lazy state has been evaluated. */
public static void unlazy(LazyForwardingEquality<?> in) {
in.state();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021 DiffPlug
* Copyright 2021-2022 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -26,6 +26,7 @@
import org.gradle.api.Task;

import com.diffplug.spotless.FileSignature;
import com.diffplug.spotless.LazyForwardingEquality;

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

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

Expand Down

0 comments on commit 2be1291

Please sign in to comment.