Skip to content

Commit f32ebe8

Browse files
committed
Fix caching memory leak in GitAttributesLineEndings.
1 parent 90778f7 commit f32ebe8

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

lib-extra/src/main/java/com/diffplug/spotless/extra/GitAttributesLineEndings.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
*/
1616
package com.diffplug.spotless.extra;
1717

18-
import static com.diffplug.spotless.extra.LibExtraPreconditions.requireElementsNonNull;
19-
2018
import java.io.File;
2119
import java.io.FileInputStream;
2220
import java.io.IOException;
@@ -78,8 +76,8 @@ public static LineEnding.Policy create(File projectDir, Supplier<Iterable<File>>
7876
static class RelocatablePolicy extends LazyForwardingEquality<CachedEndings> implements LineEnding.Policy {
7977
private static final long serialVersionUID = 5868522122123693015L;
8078

81-
final transient File projectDir;
82-
final transient Supplier<Iterable<File>> toFormat;
79+
transient File projectDir;
80+
transient Supplier<Iterable<File>> toFormat;
8381

8482
RelocatablePolicy(File projectDir, Supplier<Iterable<File>> toFormat) {
8583
this.projectDir = Objects.requireNonNull(projectDir, "projectDir");
@@ -88,8 +86,13 @@ static class RelocatablePolicy extends LazyForwardingEquality<CachedEndings> imp
8886

8987
@Override
9088
protected CachedEndings calculateState() throws Exception {
91-
Runtime runtime = new RuntimeInit(projectDir, toFormat.get()).atRuntime();
92-
return new CachedEndings(projectDir, runtime, toFormat.get());
89+
Runtime runtime = new RuntimeInit(projectDir).atRuntime();
90+
// LazyForwardingEquality guarantees that this will only be called once, and keeping toFormat
91+
// causes a memory leak, see https://github.com/diffplug/spotless/issues/1194
92+
CachedEndings state = new CachedEndings(projectDir, runtime, toFormat.get());
93+
projectDir = null;
94+
toFormat = null;
95+
return state;
9396
}
9497

9598
@Override
@@ -146,8 +149,7 @@ static class RuntimeInit {
146149
final @Nullable File workTree;
147150

148151
@SuppressFBWarnings("SIC_INNER_SHOULD_BE_STATIC_ANON")
149-
RuntimeInit(File projectDir, Iterable<File> toFormat) {
150-
requireElementsNonNull(toFormat);
152+
RuntimeInit(File projectDir) {
151153
/////////////////////////////////
152154
// USER AND SYSTEM-WIDE VALUES //
153155
/////////////////////////////////

0 commit comments

Comments
 (0)