replace init of swing components on component initialization in read action with static inner class access with no read action.

this change is needed to avoid hang between read access requires EDT access (to init jcomponent) that might be in write action (IDEA-66030)
This commit is contained in:
Maxim.Mossienko
2011-03-01 21:25:47 +03:00
parent 402d0a7565
commit 0323d1dc5a
@@ -34,7 +34,6 @@ import java.util.*;
* @author yole
*/
public class NativeFileIconProvider implements FileIconProvider {
private final JFileChooser myFileChooser = new JFileChooser();
private final Map<Ext, Icon> myIconCache = new HashMap<Ext, Icon>();
// on Windows .exe and .ico files provide their own icons which can differ for each file, cache them by full file path
private final Set<Ext> myCustomIconExtensions =
@@ -68,8 +67,8 @@ public class NativeFileIconProvider implements FileIconProvider {
return null;
}
Icon icon;
try {
icon = myFileChooser.getIcon(f);
try { // VM will ensure lock to init -static final field--, note we should have no read access here, to avoid deadlock with EDT needed to init component
icon = SwingComponentHolder.ourFileChooser.getIcon(f);
}
catch (Exception e) { // see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4854174
return null;
@@ -89,6 +88,10 @@ public class NativeFileIconProvider implements FileIconProvider {
});
}
static class SwingComponentHolder {
private static final JFileChooser ourFileChooser = new JFileChooser();
}
protected boolean isNativeFileType(VirtualFile file) {
return ElementBase.isNativeFileType(file.getFileType());
}