Skip to content

Avoid deadlock between Javascript/JSP indexers and the building process #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
package org.eclipse.jst.jsp.core.internal.contentmodel;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import org.eclipse.core.filebuffers.FileBuffers;
import org.eclipse.core.filebuffers.IDocumentSetupParticipant;
Expand Down Expand Up @@ -56,7 +56,6 @@ public class TaglibController implements IDocumentSetupParticipant, IDocumentSet

class DocumentInfo implements ITaglibIndexListener {
IStructuredDocument document;
ITextFileBuffer textFileBuffer;
IPath location;
LocationKind locationKind;
TLDCMDocumentManager tldDocumentManager;
Expand Down Expand Up @@ -128,20 +127,19 @@ public void bufferCreated(IFileBuffer buffer) {
info = _instance.fDocumentMap.get(document);
}
if (info != null) {
// remember the buffer now
info.textFileBuffer = (ITextFileBuffer) buffer;
_instance.fTextFileBufferMap.put(buffer, info);
}
else {
info = new DocumentInfo();
info.document = (IStructuredDocument) document;
info.textFileBuffer = (ITextFileBuffer) buffer;
info.location = buffer.getLocation();
info.locationKind = LocationKind.NORMALIZE;
info.tldDocumentManager = new TLDCMDocumentManager();
info.tldDocumentManager.setSourceParser((XMLSourceParser) info.document.getParser());
synchronized (_instance.fDocumentMap) {
_instance.fDocumentMap.put(document, info);
}
_instance.fTextFileBufferMap.put(buffer, info);
if (document instanceof BasicStructuredDocument && document.getLength() > 0) {
((BasicStructuredDocument) document).reparse(this);
}
Expand All @@ -156,31 +154,21 @@ public void bufferCreated(IFileBuffer buffer) {
* @see org.eclipse.core.filebuffers.IFileBufferListener#bufferDisposed(org.eclipse.core.filebuffers.IFileBuffer)
*/
public void bufferDisposed(IFileBuffer buffer) {
DocumentInfo info;

if (buffer instanceof ITextFileBuffer) {
IDocument document = ((ITextFileBuffer) buffer).getDocument();
synchronized (_instance.fJSPdocuments) {
if (!_instance.fJSPdocuments.remove(document))
return;
}
}

synchronized (fDocumentMap) {
Iterator<Entry<IDocument, DocumentInfo>> infos = fDocumentMap.entrySet().iterator();
while(infos.hasNext()) {
Entry<IDocument, DocumentInfo> entry = infos.next();
/**
* https://bugs.eclipse.org/bugs/show_bug.cgi?id=222137
*
* Might be null if setup() has been called but
* bufferCreated() has not, yet.
*/
DocumentInfo info = entry.getValue();
if (info.textFileBuffer != null && info.textFileBuffer.equals(buffer)) {
info.tldDocumentManager.clearCache();
TaglibIndex.removeTaglibIndexListener(info);
infos.remove();
break;
}
info = _instance.fTextFileBufferMap.remove(buffer);
if (info != null) {
info.tldDocumentManager.clearCache();
TaglibIndex.removeTaglibIndexListener(info);
synchronized (fDocumentMap) {
fDocumentMap.remove(info.document);
}
}
}
Expand Down Expand Up @@ -310,7 +298,7 @@ public synchronized static void startup() {
IFileBufferListener fBufferListener;

Map<IDocument, DocumentInfo> fDocumentMap;

Map<IFileBuffer, DocumentInfo> fTextFileBufferMap;
List<IDocument> fJSPdocuments;

/*
Expand All @@ -322,6 +310,7 @@ public TaglibController() {
fBufferListener = new FileBufferListener();
fJSPdocuments = new ArrayList<>(1);
fDocumentMap = new HashMap<>(1);
fTextFileBufferMap = Collections.synchronizedMap(new HashMap<>(1));
}


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

DocumentInfo info = new DocumentInfo();
info.document = (IStructuredDocument) document;
info.textFileBuffer = null; // will be supplied later
info.location = location;
info.locationKind = locationKind;
info.tldDocumentManager = new TLDCMDocumentManager();
Expand Down