ZipException: invalid distance too far back during the plugin Unload
Answered
Hello community!
I've registered a DynamicPluginListener:
<applicationListeners>
<listener
class="ai.zencoder.plugin.providers.completion.ZencoderDynamicPluginListener"
topic="com.intellij.ide.plugins.DynamicPluginListener"/>
</applicationListeners>The code is quite simple:
class ZencoderDynamicPluginListener : DynamicPluginListener {
private val logger = Logger.getInstance(ZencoderDynamicPluginListener::class.java)
override fun beforePluginUnload(pluginDescriptor: IdeaPluginDescriptor, isUpdate: Boolean) {
logger.info("Plugin about to be unloaded: start")
Sentry.close()
logger.info("Plugin about to be unloaded: ${pluginDescriptor.pluginId}, isUpdate: $isUpdate")
}
}But everytime I reload the pugin, I'm facing:
Caused by: java.lang.ClassNotFoundException: ai.zencoder.plugin.providers.completion.ZencoderDynamicPluginListener
at com.intellij.ide.plugins.cl.PluginClassLoader.tryLoadingClass(PluginClassLoader.kt:188)
at com.intellij.serviceContainer.ComponentManagerImplKt.doLoadClass(ComponentManagerImpl.kt:2255)
at com.intellij.serviceContainer.ComponentManagerImpl.createListener(ComponentManagerImpl.kt:1442)
... 55 more
Caused by: java.util.zip.ZipException: invalid distance too far back
at com.intellij.util.lang.ImmutableZipEntry.getByteBuffer(ImmutableZipEntry.java:149)
at com.intellij.util.lang.HashMapZipFile.getByteBuffer(HashMapZipFile.java:99)
at com.intellij.util.lang.ZipResourceFile.findClass(ZipResourceFile.java:107)
at com.intellij.util.lang.JarLoader.findClass(JarLoader.java:58)
at com.intellij.util.lang.ClassPath.findClassInLoader(ClassPath.java:240)
at com.intellij.util.lang.ClassPath.findClass(ClassPath.java:190)
at com.intellij.ide.plugins.cl.PluginClassLoader.loadClassInsideSelf(PluginClassLoader.kt:326)
at com.intellij.ide.plugins.cl.PluginClassLoader.tryLoadingClass(PluginClassLoader.kt:178)I've tried to recreate the class, clean build, move packages to avoid any possibilities of the file corruption, but still didn't succeed.
If you have any suggestions, would be appreciated.
Please sign in to leave a comment.
Hi,
It's hard to tell what can be the reason. Does it happen during development or for regular users in the actual IDE? What is the IDE version (and project setup if it happens during development)? Does it happen when you delete the listener? What if you leave the
beforePluginUnloadempty?Hi Karol Lewandowski , thanks for the reply!
It is regarding the development.
IDE: I tried various ones from IU 2023.3.1 to 2024.2.0.1, with corresponding JDK 17 for lower versions and JDK21 for higher.
It happens during the dynamic plugin reload, when I perform some changes and run the buildPlugin task.
The same behavior when beforePluginUnload is empty, the same even if I don't declare any methods in the class. If I remove the listener registration in plugin.xml, the problem disapears (but I don't get my desired functionality :)
Please let me know if you need any other information about the project setup or any inputs.
One more question: is the problem gone when you build and install the plugin in a regular IDE?
Yes it is gone, the exception is raised only during the reload, when it tries to invoke the DynamicPluginListener and the classLoader tries to load the class.
PS the class is present in the distribution.
It sounds like the archive is corrupted after rebuilding the plugin (the error indicated the ZIP archive corruption). Please report it at https://github.com/JetBrains/intellij-platform-gradle-plugin/issues, ideally with a sample plugin project and steps to reproduce.