How to remove an order entry?

code:

ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module);
OrderEntry[] orderEntries = moduleRootManager.getOrderEntries();
ModifiableRootModel modifiableRootModel = moduleRootManager.getModifiableModel();
LibraryTable moduleLibraryTable = modifiableRootModel.getModuleLibraryTable();
for (OrderEntry orderEntry : orderEntries) {
    if (!orderEntry.isValid()) { 
       modifiableRootModel.removeOrderEntry(orderEntry);
    }
}
modifiableRootModel.commit();


but I got an exception:

Assertion failed:
java.lang.Throwable
at com.intellij.openapi.diagnostic.Logger.assertTrue(Logger.java:89)
at com.intellij.openapi.diagnostic.Logger.assertTrue(Logger.java:96)
at com.intellij.openapi.roots.impl.RootModelImpl.a(RootModelImpl.java:431)
at com.intellij.openapi.roots.impl.RootModelImpl.removeOrderEntry(RootModelImpl.java:206)

Please sign in to leave a comment.