mirror of
https://gitee.com/dcren/initializr.git
synced 2026-02-25 21:22:58 +08:00
Fix thread-safety access in ProjectGenerationInvoker
See gh-1125
This commit is contained in:
committed by
Stephane Nicoll
parent
907d639946
commit
fd6bc357c2
@@ -20,9 +20,9 @@ import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import io.spring.initializr.generator.buildsystem.BuildItemResolver;
|
||||
import io.spring.initializr.generator.buildsystem.BuildWriter;
|
||||
@@ -56,7 +56,7 @@ public class ProjectGenerationInvoker<R extends ProjectRequest> {
|
||||
|
||||
private final ProjectRequestToDescriptionConverter<R> requestConverter;
|
||||
|
||||
private transient Map<Path, List<Path>> temporaryFiles = new LinkedHashMap<>();
|
||||
private transient Map<Path, List<Path>> temporaryFiles = new ConcurrentHashMap<>();
|
||||
|
||||
public ProjectGenerationInvoker(ApplicationContext parentApplicationContext,
|
||||
ProjectRequestToDescriptionConverter<R> requestConverter) {
|
||||
@@ -143,7 +143,14 @@ public class ProjectGenerationInvoker<R extends ProjectRequest> {
|
||||
}
|
||||
|
||||
private void addTempFile(Path group, Path file) {
|
||||
this.temporaryFiles.computeIfAbsent(group, (key) -> new ArrayList<>()).add(file);
|
||||
this.temporaryFiles.compute(group, (path, paths) -> {
|
||||
List<Path> newPaths = paths;
|
||||
if (newPaths == null) {
|
||||
newPaths = new ArrayList<>();
|
||||
}
|
||||
newPaths.add(file);
|
||||
return newPaths;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user