Gradle sync failed with AlreadyDisposedException when loading previously unloaded module in Android Studio 2020.3.1

Answered

I have been facing this issue whenever I trigger Gradle sync after loading modules. I am developing a plugin to automatically load/unload modules and I was getting this exception. I thought this might be my programming error but I was able to reproduce the issue in the IDE itself.

Step to reproduce:

  1. Unload a module from the project.
  2. Perform Gradle sync.
  3. Load the module from the project.
  4. Perform Gradle sync again.

I am getting this exception

Caused by: com.intellij.serviceContainer.AlreadyDisposedException: Already disposed: Module: 'ModuleLoaderTest.features.FeatureB' (disposed)
at com.intellij.serviceContainer.ComponentManagerImpl.getMessageBus(ComponentManagerImpl.kt:175)
at com.android.tools.idea.model.AndroidModel.set(AndroidModel.java:61)
at com.android.tools.idea.projectsystem.gradle.sync.AndroidModuleDataServiceKt.configureFacet(AndroidModuleDataService.kt:285)
at com.android.tools.idea.projectsystem.gradle.sync.AndroidModuleDataServiceKt.access$configureFacet(AndroidModuleDataService.kt:1)
at com.android.tools.idea.projectsystem.gradle.sync.AndroidModuleDataService.importData(AndroidModuleDataService.kt:129)
at com.android.tools.idea.gradle.project.sync.idea.data.service.ModuleModelDataService.lambda$importData$0(ModuleModelDataService.java:46)
at com.intellij.openapi.command.WriteCommandAction.lambda$runWriteCommandAction$5(WriteCommandAction.java:362)
at com.intellij.openapi.command.WriteCommandAction$BuilderImpl$1.run(WriteCommandAction.java:112)
at com.intellij.openapi.application.RunResult.run(RunResult.java:35)
at com.intellij.openapi.command.WriteCommandAction.lambda$performWriteCommandAction$1(WriteCommandAction.java:253)
at com.intellij.openapi.application.impl.ApplicationImpl.runWriteAction(ApplicationImpl.java:1006)
at com.intellij.openapi.command.WriteCommandAction.lambda$performWriteCommandAction$2(WriteCommandAction.java:252)
at com.intellij.openapi.command.WriteCommandAction.lambda$doExecuteCommand$4(WriteCommandAction.java:310)
at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:220)
at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:187)
at com.intellij.openapi.command.WriteCommandAction.doExecuteCommand(WriteCommandAction.java:312)
at com.intellij.openapi.command.WriteCommandAction.performWriteCommandAction(WriteCommandAction.java:251)
at com.intellij.openapi.command.WriteCommandAction.lambda$execute$0(WriteCommandAction.java:236)
at com.intellij.openapi.application.TransactionGuardImpl.runWithWritingAllowed(TransactionGuardImpl.java:216)
at com.intellij.openapi.application.TransactionGuardImpl.access$200(TransactionGuardImpl.java:24)
at com.intellij.openapi.application.TransactionGuardImpl$2.run(TransactionGuardImpl.java:199)
at com.intellij.openapi.application.impl.ApplicationImpl.runIntendedWriteActionOnCurrentThread(ApplicationImpl.java:828)
at com.intellij.openapi.application.impl.ApplicationImpl.lambda$invokeAndWait$8(ApplicationImpl.java:482)
at com.intellij.openapi.application.impl.LaterInvocator$1.run(LaterInvocator.java:127)
at com.intellij.openapi.application.impl.FlushQueue.doRun(FlushQueue.java:85)
at com.intellij.openapi.application.impl.FlushQueue.runNextEvent(FlushQueue.java:134)
at com.intellij.openapi.application.impl.FlushQueue.flushNow(FlushQueue.java:47)
at com.intellij.openapi.application.impl.FlushQueue$FlushNow.run(FlushQueue.java:190)
at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:313)
at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:770)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:715)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:740)
at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.java:976)
Caused by: com.intellij.serviceContainer.AlreadyDisposedException: Already disposed: Module: 'ModuleLoaderTest.features.FeatureB' (disposed)

 

0
3 comments

Is it reproduced in IntelliJ IDEA? Seems to be Android Studio - specific problem. 

0

I have reproduced this problem in Intellij IDEA version 2021.2.2. I think when we trigger Gradle sync after unloading the module then it might be removed from Gradle (I don't know much about that, just my guess). Then when we load the module and trigger sync again then it will be loaded in IDEA but not in gradle. Anyways, the problem is there.

0

I've created bug request to investigate that: https://youtrack.jetbrains.com/issue/IDEA-281208

Please share logs folder compressed inside this request to check the exact error and your environemnt. You can do that privately. 

0

Please sign in to leave a comment.