File tree Expand file tree Collapse file tree
jib-core/src/main/java/com/google/cloud/tools/jib/filesystem Expand file tree Collapse file tree Original file line number Diff line number Diff line change 3131/** Creates and deletes lock files. */
3232public class LockFile implements Closeable {
3333
34- private static final ConcurrentHashMap <Path , Lock > lockMap = new ConcurrentHashMap <>();
34+ // In Gradle composite builds with independent buildSrc directories, each included build loads
35+ // jib-core in its own classloader. A normal static field creates separate lockMap instances per
36+ // classloader, failing to prevent concurrent FileChannel.lock() calls on the same file and
37+ // causing OverlappingFileLockException (#3347). This is admittedly a hack, but there is no
38+ // clean way to share state across classloaders in the same JVM. System.getProperties() returns
39+ // the same Hashtable regardless of classloader, so it serves as a JVM-global namespace.
40+ // The map's key/value types (Path, Lock) are bootstrap-loaded, so they're safe to cast.
41+ @ SuppressWarnings ("unchecked" )
42+ private static final ConcurrentHashMap <Path , Lock > lockMap =
43+ (ConcurrentHashMap <Path , Lock >)
44+ System .getProperties ()
45+ .computeIfAbsent (
46+ "jib.lockFile.lockMap" , key -> new ConcurrentHashMap <Path , Lock >());
3547
3648 private final Path lockFilePath ;
3749 private final FileLock fileLock ;
You can’t perform that action at this time.
0 commit comments