Skip to content

Commit edd39ae

Browse files
committed
Avoid deadlock between Javascript/JSP indexers and the building process
1 parent 6824711 commit edd39ae

File tree

1 file changed

+13
-25
lines changed
  • web/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/contentmodel

1 file changed

+13
-25
lines changed

web/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/contentmodel/TaglibController.java

+13-25
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
package org.eclipse.jst.jsp.core.internal.contentmodel;
1515

1616
import java.util.ArrayList;
17+
import java.util.Collections;
1718
import java.util.HashMap;
1819
import java.util.Iterator;
1920
import java.util.List;
2021
import java.util.Map;
21-
import java.util.Map.Entry;
2222

2323
import org.eclipse.core.filebuffers.FileBuffers;
2424
import org.eclipse.core.filebuffers.IDocumentSetupParticipant;
@@ -56,7 +56,6 @@ public class TaglibController implements IDocumentSetupParticipant, IDocumentSet
5656

5757
class DocumentInfo implements ITaglibIndexListener {
5858
IStructuredDocument document;
59-
ITextFileBuffer textFileBuffer;
6059
IPath location;
6160
LocationKind locationKind;
6261
TLDCMDocumentManager tldDocumentManager;
@@ -128,20 +127,19 @@ public void bufferCreated(IFileBuffer buffer) {
128127
info = _instance.fDocumentMap.get(document);
129128
}
130129
if (info != null) {
131-
// remember the buffer now
132-
info.textFileBuffer = (ITextFileBuffer) buffer;
130+
_instance.fTextFileBufferMap.put(buffer, info);
133131
}
134132
else {
135133
info = new DocumentInfo();
136134
info.document = (IStructuredDocument) document;
137-
info.textFileBuffer = (ITextFileBuffer) buffer;
138135
info.location = buffer.getLocation();
139136
info.locationKind = LocationKind.NORMALIZE;
140137
info.tldDocumentManager = new TLDCMDocumentManager();
141138
info.tldDocumentManager.setSourceParser((XMLSourceParser) info.document.getParser());
142139
synchronized (_instance.fDocumentMap) {
143140
_instance.fDocumentMap.put(document, info);
144141
}
142+
_instance.fTextFileBufferMap.put(buffer, info);
145143
if (document instanceof BasicStructuredDocument && document.getLength() > 0) {
146144
((BasicStructuredDocument) document).reparse(this);
147145
}
@@ -156,31 +154,21 @@ public void bufferCreated(IFileBuffer buffer) {
156154
* @see org.eclipse.core.filebuffers.IFileBufferListener#bufferDisposed(org.eclipse.core.filebuffers.IFileBuffer)
157155
*/
158156
public void bufferDisposed(IFileBuffer buffer) {
157+
DocumentInfo info;
158+
159159
if (buffer instanceof ITextFileBuffer) {
160160
IDocument document = ((ITextFileBuffer) buffer).getDocument();
161161
synchronized (_instance.fJSPdocuments) {
162162
if (!_instance.fJSPdocuments.remove(document))
163163
return;
164164
}
165165
}
166-
167-
synchronized (fDocumentMap) {
168-
Iterator<Entry<IDocument, DocumentInfo>> infos = fDocumentMap.entrySet().iterator();
169-
while(infos.hasNext()) {
170-
Entry<IDocument, DocumentInfo> entry = infos.next();
171-
/**
172-
* https://bugs.eclipse.org/bugs/show_bug.cgi?id=222137
173-
*
174-
* Might be null if setup() has been called but
175-
* bufferCreated() has not, yet.
176-
*/
177-
DocumentInfo info = entry.getValue();
178-
if (info.textFileBuffer != null && info.textFileBuffer.equals(buffer)) {
179-
info.tldDocumentManager.clearCache();
180-
TaglibIndex.removeTaglibIndexListener(info);
181-
infos.remove();
182-
break;
183-
}
166+
info = _instance.fTextFileBufferMap.remove(buffer);
167+
if (info != null) {
168+
info.tldDocumentManager.clearCache();
169+
TaglibIndex.removeTaglibIndexListener(info);
170+
synchronized (fDocumentMap) {
171+
fDocumentMap.remove(info.document);
184172
}
185173
}
186174
}
@@ -310,7 +298,7 @@ public synchronized static void startup() {
310298
IFileBufferListener fBufferListener;
311299

312300
Map<IDocument, DocumentInfo> fDocumentMap;
313-
301+
Map<IFileBuffer, DocumentInfo> fTextFileBufferMap;
314302
List<IDocument> fJSPdocuments;
315303

316304
/*
@@ -322,6 +310,7 @@ public TaglibController() {
322310
fBufferListener = new FileBufferListener();
323311
fJSPdocuments = new ArrayList<>(1);
324312
fDocumentMap = new HashMap<>(1);
313+
fTextFileBufferMap = Collections.synchronizedMap(new HashMap<>(1));
325314
}
326315

327316

@@ -359,7 +348,6 @@ public void setup(IDocument document, IPath location, LocationKind locationKind)
359348

360349
DocumentInfo info = new DocumentInfo();
361350
info.document = (IStructuredDocument) document;
362-
info.textFileBuffer = null; // will be supplied later
363351
info.location = location;
364352
info.locationKind = locationKind;
365353
info.tldDocumentManager = new TLDCMDocumentManager();

0 commit comments

Comments
 (0)