Uploaded image for project: 'Spigot'
  1. Spigot
  2. SPIGOT-7145

PluginClassLoader does not re-open JarFile upon enabling a previously disabled JavaPlugin

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • None
    • None
    • None
    • While the test environment has Paper and PlugManX, the source code links below indicate that this continues to be a problem on the master branch

    • This server is running Paper version git-Paper-788 (MC: 1.16.5) (Implementing API version 1.16.5-R0.1-SNAPSHOT)
    • PlugManX
    • Yes

      Reproducible example (see attached plugin jar): 

      • onEnable: Attempt to do Class#forName(String) for some class that is not present on the classpath (in a try/catch for ClassNotFoundException)
      • When the server starts and calls onEnable, JarFile will be open, so no IllegalStateException is thrown from PluginClassLoader
      • Disable the plugin. This results in JarFile#close
      • Enable the plugin. The same Class#forName(String) call will trigger PluginClassLoader#findClass(String). Now, however, jar is closed, so an IllegalStateException is thrown

       

      This is caused by the same PluginClassLoader being used in #enablePlugin, even after a call to #close.

       

      Further, no attempt is made to re-open the plugin JarFile on re-enable, resulting in this IllegalStateException

       

      java.lang.IllegalStateException: zip file closed
          at java.util.zip.ZipFile.ensureOpen(Unknown Source)
          at java.util.zip.ZipFile.getEntry(Unknown Source)
          at java.util.jar.JarFile.getEntry(Unknown Source)
          at java.util.jar.JarFile.getJarEntry(Unknown Source)
          at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:167)
          at java.lang.ClassLoader.loadClass(Unknown Source)
          at org.bukkit.plugin.java.PluginClassLoader.loadClass0(PluginClassLoader.java:119)
          at org.bukkit.plugin.java.PluginClassLoader.loadClass(PluginClassLoader.java:114)
          at java.lang.ClassLoader.loadClass(Unknown Source)
          at java.lang.Class.forName0(Native Method)
          at java.lang.Class.forName(Unknown Source)
          at io.github.iprodigy.bugreport.PluginClassLoaderClosedJarFileExample.onEnable(PluginClassLoaderClosedJarFileExample.java:10)
          at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:263)
          at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:370)
          at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:500)
      

       

      If this is accepted as a bug, I can submit a potential patch for consideration.

            Unassigned Unassigned
            iProdigy Prodigy
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: