diff --git a/java/java-tests/testSrc/com/intellij/roots/libraries/LibraryTest.java b/java/java-tests/testSrc/com/intellij/roots/libraries/LibraryTest.java index 55e15c54a4bd..e5d0f05cf5ed 100644 --- a/java/java-tests/testSrc/com/intellij/roots/libraries/LibraryTest.java +++ b/java/java-tests/testSrc/com/intellij/roots/libraries/LibraryTest.java @@ -160,6 +160,22 @@ public class LibraryTest extends ModuleRootManagerTestCase { assertEquals("b", assertOneElement(getLibraryTable().getLibraries()).getName()); } + public void testReloadLibraryTableWithoutChanges() { + ((LibraryTableBase)getLibraryTable()).loadState(new Element("component")); + createLibrary("a", null, null); + ((LibraryTableBase)getLibraryTable()).loadState(new Element("component").addContent(new Element("library").setAttribute("name", "a"))); + assertEquals("a", assertOneElement(getLibraryTable().getLibraries()).getName()); + } + + public void testNonCommittedLibraryIsDisposed() { + LibraryTable table = getLibraryTable(); + LibraryTable.ModifiableModel model = table.getModifiableModel(); + Library library = model.createLibrary("a"); + model.removeLibrary(library); + commit(model); + assertEmpty(table.getLibraries()); + } + public void testResolveDependencyToRenamedLibrary() { Library library = createLibrary("jdom2", getJDomJar(), null); diff --git a/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/libraries/LibraryTableBase.java b/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/libraries/LibraryTableBase.java index 4b62cd9d50d2..545e68f99a66 100644 --- a/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/libraries/LibraryTableBase.java +++ b/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/libraries/LibraryTableBase.java @@ -19,7 +19,6 @@ import com.intellij.openapi.util.registry.Registry; import com.intellij.openapi.util.text.StringUtil; import com.intellij.util.EventDispatcher; import com.intellij.util.containers.ContainerUtil; -import java.util.HashSet; import org.jdom.Element; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; @@ -180,7 +179,8 @@ public abstract class LibraryTableBase implements PersistentStateComponent removedLibraries = ContainerUtil.newIdentityTroveSet(myModel.myLibraries); removedLibraries.removeAll(model.myLibraries); - + model.myLibrariesToDispose.removeAll(model.myLibraries); + model.myLibrariesToDispose.removeAll(myModel.myLibraries); for (Library library : removedLibraries) { fireBeforeLibraryRemoved(library); } @@ -211,6 +211,7 @@ public abstract class LibraryTableBase implements PersistentStateComponent myLibraries = new ArrayList<>(); + private final Set myLibrariesToDispose = ContainerUtil.newIdentityTroveSet(); private volatile Map myLibraryByNameCache; private boolean myWritable; @@ -234,6 +235,9 @@ public abstract class LibraryTableBase implements PersistentStateComponent