diff --git a/platform/lang-impl/src/com/intellij/util/ui/classpath/SimpleClasspathPanel.java b/platform/lang-impl/src/com/intellij/util/ui/classpath/SimpleClasspathPanel.java index aa6db97240f2..05ee68ba51fa 100644 --- a/platform/lang-impl/src/com/intellij/util/ui/classpath/SimpleClasspathPanel.java +++ b/platform/lang-impl/src/com/intellij/util/ui/classpath/SimpleClasspathPanel.java @@ -163,12 +163,14 @@ public class SimpleClasspathPanel extends JPanel { list.scrollRectToVisible(cellRect); } - private static Collection ensureApplicationLevel(final Library library, final Set existingFiles) { + private static Collection ensureApplicationLevel(final Library library, final Set existingFiles, + final Disposable parentDisposable) { if (library.getTable() == null || !LibraryTablesRegistrar.APPLICATION_LEVEL.equals(library.getTable().getTableLevel())) { final ArrayList result = new ArrayList(); for (VirtualFile file : library.getFiles(OrderRootType.CLASSES)) { if (!existingFiles.add(file)) continue; final Library newLibrary = LibraryTableImplUtil.createModuleLevelLibrary(null, null); + Disposer.register(parentDisposable, newLibrary); final Library.ModifiableModel libModel = newLibrary.getModifiableModel(); libModel.addRoot(file, OrderRootType.CLASSES); libModel.commit(); @@ -264,7 +266,7 @@ public class SimpleClasspathPanel extends JPanel { final List libraries = dialog.getSelectedLibraries(); final ArrayList result = new ArrayList(); for (Library o : libraries) { - result.addAll(ensureApplicationLevel(o, existingFiles)); + result.addAll(ensureApplicationLevel(o, existingFiles, myDisposable)); } return result; }