GH-1535: avoid concurrent modification exception by synchronizing access to the list of symbols for a specific project

Fixes GH-1535
This commit is contained in:
Martin Lippert
2025-04-10 15:48:48 +02:00
parent 8cf3836ed7
commit 7b795b54fc

View File

@@ -605,23 +605,25 @@ public class SpringSymbolIndex implements InitializingBean, SpringIndex {
private Collection<? extends String> getDocsFromPath(IJavaProject project, String path) {
List<WorkspaceSymbol> allProjectSymbols = this.symbolsByProject.get(project.getElementName());
Set<String> result = new HashSet<>();
if (allProjectSymbols != null) {
for (WorkspaceSymbol symbol : allProjectSymbols) {
Either<Location, WorkspaceSymbolLocation> location = symbol.getLocation();
String docURI = null;
if (location.isLeft()) {
docURI = location.getLeft().getUri();
}
else if (location.isRight()) {
docURI = location.getRight().getUri();
}
if (docURI != null && docURI.startsWith(path)) {
result.add(docURI);
synchronized(allProjectSymbols) {
for (WorkspaceSymbol symbol : allProjectSymbols) {
Either<Location, WorkspaceSymbolLocation> location = symbol.getLocation();
String docURI = null;
if (location.isLeft()) {
docURI = location.getLeft().getUri();
}
else if (location.isRight()) {
docURI = location.getRight().getUri();
}
if (docURI != null && docURI.startsWith(path)) {
result.add(docURI);
}
}
}
}