Skip to content

Commit 3226d2b

Browse files
authored
Add log on new FeatureClassLoader as it may help leak investigations (#1558)
2 parents 365d320 + 64d5700 commit 3226d2b

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2021 DiffPlug
2+
* Copyright 2016-2023 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.
@@ -27,13 +27,18 @@
2727

2828
import javax.annotation.Nullable;
2929

30+
import org.slf4j.Logger;
31+
import org.slf4j.LoggerFactory;
32+
3033
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
3134

3235
/**
3336
* Spotless' global cache. {@link SpotlessCache#clear()} should be called
3437
* when Spotless is no longer in use to release any resources it has grabbed.
3538
*/
3639
public final class SpotlessCache {
40+
private static final Logger LOGGER = LoggerFactory.getLogger(SpotlessCache.class);
41+
3742
/** Allows comparing keys based on their serialization. */
3843
static final class SerializedKey {
3944
final byte[] serialized;
@@ -68,7 +73,10 @@ synchronized ClassLoader classloader(JarState state) {
6873
synchronized ClassLoader classloader(Serializable key, JarState state) {
6974
SerializedKey serializedKey = new SerializedKey(key);
7075
return cache
71-
.computeIfAbsent(serializedKey, k -> new FeatureClassLoader(state.jarUrls(), this.getClass().getClassLoader()));
76+
.computeIfAbsent(serializedKey, k -> {
77+
LOGGER.debug("Allocating an additional FeatureClassLoader for key={} Cache.size was {}", key, cache.size());
78+
return new FeatureClassLoader(state.jarUrls(), this.getClass().getClassLoader());
79+
});
7280
}
7381

7482
static SpotlessCache instance() {

0 commit comments

Comments
 (0)