Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6392760

Clearing cache while running VM causes plugin NullPointerException

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Won't Fix
    • Icon: P4 P4
    • None
    • 5.0
    • deploy
    • x86
    • windows_xp

      FULL PRODUCT VERSION :
      Java 1.5.0_04 (build 1.5.0_04-b05)

      ADDITIONAL OS VERSION INFORMATION :
      Windows XP Professional Edition - SP2

      A DESCRIPTION OF THE PROBLEM :
      Launching a Pogo game (any applet that would need sound or image assets) causes the following console output to occur (or something similar, key point is the sun.plugin.cache.Cache.updateTable() line):

      java.lang.NullPointerException
                  at sun.plugin.cache.Cache.updateTable(Unknown Source)
                  at sun.plugin.cache.FileCache.getMatchingFile(Unknown Source)
                  at sun.plugin.cache.CachedFileLoader$2.run(Unknown Source)
                  at java.security.AccessController.doPrivileged(Native Method)
                  at sun.plugin.cache.CachedFileLoader.getCacheFile(Unknown Source)
                  at sun.plugin.cache.CachedFileLoader.load(Unknown Source)
                  at sun.plugin.cache.FileCache.get(Unknown Source)
                  at sun.plugin.cache.PluginCacheHandler.get(Unknown Source)
                  at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
                  at sun.net.www.protocol.http.HttpURLConnection.connect(Unknown Source)
                  at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
                  at sun.awt.image.URLImageSource.getDecoder(Unknown Source) at sun.awt.image.InputStreamImageSource.doFetch(Unknown Source)
                  at sun.awt.image.ImageFetcher.fetchloop(Unknown Source)
                  at sun.awt.image.ImageFetcher.run(Unknown Source)

       
      The game will then stall. Relaunching the game will just stall again, may not show the NPE again, though.

       
      The problem is in the Sun browser plugin classes provided as plugin.jar in the Sun JRE. The cause is that the Cache class assumes that the directory it thinks the cached assets are in is always there for the duration of its runtime. After clearing the asset cache, all of the directories in the cache are removed, so the Cache class ends up trying to list the files on a path that does not exist. The problem corrects itself when the plugin is restarted because it rebuilds its table appropriately.

       
      The class sun.plugin.cache.FileCache assumes the directory of cached files remains constant and passes the same File reference to its updateTable() call. However, when you clear the asset cache, the directory it is linked to no longer exists. So, in updateTable() in sun.plugin.cache.Cache, line 283 returns a null for the File[] array afile because the directory that "file" refers to is nonexistent, and the API for listFiles() states it will return null if the path does not denote a directory, which it doesn't, or an IOException occurs, which probably it did and was silenced.

      If it returned an empty array, that would have been fine, or checked for a null return value before it used the array in a for loop in the following line, then it would have counted CORRECTLY as a cache miss, but it assumes that at the very least, the directory is there, and so it fails miserably.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Your browser and VM must already be running when you clear the cache (through Control Panel->Java->Delete Files...). You can use IE or Firefox in Windows and launch a game, THEN clear the cache with the browser open, then try launching that or any other game. The console will show the NPE when loading assets.

      If you shutdown the VM plugin and restart it (kill all IE or Firefox windows and open them again), the problem will disappear.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Cache logic should realize that the requested asset is no longer available, that in fact, the directory itself no longer exists, and recreate the directory and the asset.
      ACTUAL -
      The cache logic tries to list the files for a non-existant directory and throws a NullPointerException when checking whether it has the asset cached.

      ERROR MESSAGES/STACK TRACES THAT OCCUR :

      java.lang.NullPointerException
                  at sun.plugin.cache.Cache.updateTable(Unknown Source)
                  at sun.plugin.cache.FileCache.getMatchingFile(Unknown Source)
                  at sun.plugin.cache.CachedFileLoader$2.run(Unknown Source)
                  at java.security.AccessController.doPrivileged(Native Method)
                  at sun.plugin.cache.CachedFileLoader.getCacheFile(Unknown Source)
                  at sun.plugin.cache.CachedFileLoader.load(Unknown Source)
                  at sun.plugin.cache.FileCache.get(Unknown Source)
                  at sun.plugin.cache.PluginCacheHandler.get(Unknown Source)
                  at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
                  at sun.net.www.protocol.http.HttpURLConnection.connect(Unknown Source)
                  at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
                  at sun.awt.image.URLImageSource.getDecoder(Unknown Source) at sun.awt.image.InputStreamImageSource.doFetch(Unknown Source)
                  at sun.awt.image.ImageFetcher.fetchloop(Unknown Source)
                  at sun.awt.image.ImageFetcher.run(Unknown Source)


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      Any applet code that requests an image or sound asset will suffice for this test.
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Restart the browser/VM which rebuilds the index of the cache. Actual fix included in description. Clear the cache before VM is started.

            dgu Dennis Gu (Inactive)
            gmanwanisunw Girish Manwani (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: