Mac: 100% CPU and hang on shutdown (IDEA-74601)
authorNikolay Matveev <Nikolay.Matveev@jetbrains.com>
Tue, 4 Oct 2011 15:45:28 +0000 (19:45 +0400)
committerNikolay Matveev <Nikolay.Matveev@jetbrains.com>
Tue, 4 Oct 2011 16:04:11 +0000 (20:04 +0400)
platform/lang-impl/src/com/intellij/openapi/fileTypes/FileTypeUsagesCollector.java

index a29639cf9ad2aabb8ca4c84ef9184050eba6c143..a93b73fae882e3785cc1225f5bd6c7a02aa17a80 100644 (file)
@@ -18,6 +18,7 @@ package com.intellij.openapi.fileTypes;
 import com.intellij.internal.statistic.AbstractApplicationUsagesCollector;
 import com.intellij.internal.statistic.beans.GroupDescriptor;
 import com.intellij.internal.statistic.beans.UsageDescriptor;
+import com.intellij.openapi.application.ApplicationManager;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.vfs.VirtualFile;
 import com.intellij.psi.search.FileTypeIndex;
@@ -45,23 +46,30 @@ public class FileTypeUsagesCollector extends AbstractApplicationUsagesCollector
 
   @NotNull
   @Override
-  public Set<UsageDescriptor> getProjectUsages(@NotNull Project project) {
+  public Set<UsageDescriptor> getProjectUsages(@NotNull final Project project) {
     final Set<FileType> usedFileTypes = new HashSet<FileType>();
-    final FileType[] registeredFileTypes = FileTypeManager.getInstance().getRegisteredFileTypes();
-    for (final FileType fileType : registeredFileTypes) {
-      FileBasedIndex.getInstance().processValues(
-        FileTypeIndex.NAME,
-        fileType,
-        null,
-        new FileBasedIndex.ValueProcessor<Void>() {
-          @Override
-          public boolean process(VirtualFile file, Void value) {
-            usedFileTypes.add(fileType);
-            return false;
+    ApplicationManager.getApplication().runReadAction(new Runnable() {
+      @Override
+      public void run() {
+        if (!project.isDisposed()) {
+          final FileType[] registeredFileTypes = FileTypeManager.getInstance().getRegisteredFileTypes();
+          for (final FileType fileType : registeredFileTypes) {
+            FileBasedIndex.getInstance().processValues(
+              FileTypeIndex.NAME,
+              fileType,
+              null,
+              new FileBasedIndex.ValueProcessor<Void>() {
+                @Override
+                public boolean process(VirtualFile file, Void value) {
+                  usedFileTypes.add(fileType);
+                  return false;
+                }
+              }, GlobalSearchScope.projectScope(project));
           }
-        }, GlobalSearchScope.projectScope(project));
-    }
-    usedFileTypes.add(UnknownFileType.INSTANCE);
+          usedFileTypes.add(UnknownFileType.INSTANCE);
+        }
+      }
+    });
     return ContainerUtil.map2Set(usedFileTypes, new NotNullFunction<FileType, UsageDescriptor>() {
       @NotNull
       @Override