diff --git a/java/idea-ui/src/com/intellij/facet/impl/autodetecting/FacetAutodetectingManagerImpl.java b/java/idea-ui/src/com/intellij/facet/impl/autodetecting/FacetAutodetectingManagerImpl.java index 96b0133e9594..ac114322ae6b 100644 --- a/java/idea-ui/src/com/intellij/facet/impl/autodetecting/FacetAutodetectingManagerImpl.java +++ b/java/idea-ui/src/com/intellij/facet/impl/autodetecting/FacetAutodetectingManagerImpl.java @@ -76,6 +76,7 @@ public class FacetAutodetectingManagerImpl extends FacetAutodetectingManager imp private boolean myDetectionInProgress; private final Set> myFacetTypesWithDetectors = new THashSet>(); private final EnableAutodetectionWorker myEnableAutodetectionWorker; + private final Object myLock = new Object(); public FacetAutodetectingManagerImpl(final Project project, PsiManager psiManager, FacetPointersManager facetPointersManager) { myProject = project; @@ -162,22 +163,24 @@ public class FacetAutodetectingManagerImpl extends FacetAutodetectingManager imp Collection detectors = myDetectors.get(fileType); if (detectors == null) return; - List> facets = null; - for (FacetDetectorWrapper detector : detectors) { - facets = process(file, fileContent, detector, facets); - } + synchronized (myLock) { + List> facets = null; + for (FacetDetectorWrapper detector : detectors) { + facets = process(file, fileContent, detector, facets); + } - String url = file.getUrl(); - FacetDetectionIndexEntry indexEntry = myFileIndex.getIndexEntry(url); - if (indexEntry == null) { - indexEntry = new FacetDetectionIndexEntry(file.getTimeStamp()); - } + String url = file.getUrl(); + FacetDetectionIndexEntry indexEntry = myFileIndex.getIndexEntry(url); + if (indexEntry == null) { + indexEntry = new FacetDetectionIndexEntry(file.getTimeStamp()); + } - Collection removed = indexEntry.update(myFacetPointersManager, facets); - myFileIndex.putIndexEntry(url, indexEntry); + Collection removed = indexEntry.update(myFacetPointersManager, facets); + myFileIndex.putIndexEntry(url, indexEntry); - if (removed != null) { - removeObsoleteFacets(removed); + if (removed != null) { + removeObsoleteFacets(removed); + } } }