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

java.io.IOException: Invalid jar file when accessing resources in a pack.gz jar

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P3
    • Resolution: Duplicate
    • Affects Version/s: 7u21
    • Fix Version/s: 7u25
    • Component/s: deploy
    • Labels:
    • Subcomponent:
    • Resolved In Build:
      b11
    • OS:
      windows

      Description

      FULL PRODUCT VERSION :
      Java Plug-in 10.21.2.11
      Using JRE version 1.7.0_21-b11 Java HotSpot(TM) Client VM

      ADDITIONAL OS VERSION INFORMATION :
      Reproducable on Windows systems, not reproducable on OS X

      A DESCRIPTION OF THE PROBLEM :
      A simple pack200 compressed applet which accesses (by getClass().getResource()) a file inside its own JAR file throws a " java.io.IOException: Invalid jar file " if the " Keep temporary files on my computer " option is disabled in JCP.

      This happens on the first load and consequent reloads in a browser session until the class loader cache is cleared by pressing " x " in the Java console.

      The issue reoccurs when closing / reopening the browser.

      When accessing the resource with getClass().getResourceAsStream() the error does not occur.

      REGRESSION. Last worked in version 7u17

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Use sample applet class
      2. Add test.txt on the same level of the class
      3. Create JAR, sign and pack200 it
      4. Create HTML to load applet in browser
      5. Disable " Keep temporary files on my computer " option in JCP
      5. Load applet in browser

      Or access:
      - http://www.realobjects.com/fileadmin/products/testapplet/oracle-bug/pack200-ie.html for Internet Explorer
      - http://www.realobjects.com/fileadmin/products/testapplet/oracle-bug/pack200.html for other browsers





      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      No exception
      ACTUAL -
      java.io.IOException: Invalid jar file when trying to access the txt file with

      URL url = getClass().getResource( " /test.txt " );

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      Java Plug-in 10.21.2.11
      Using JRE version 1.7.0_21-b11 Java HotSpot(TM) Client VM
      User home directory = C:\Users\sebastian.giffhorn
      ----------------------------------------------------
      c: clear console window
      f: finalize objects on finalization queue
      g: garbage collect
      h: display this help message
      l: dump classloader list
      m: print memory usage
      o: trigger logging
      q: hide console
      r: reload policy configuration
      s: dump system and deployment properties
      t: dump thread list
      v: dump thread stack
      x: clear classloader cache
      0-5: set trace level to <n>
      ----------------------------------------------------
      basic: Starting applet teardown
      basic: Finished applet teardown
      basic: Removed progress listener: sun.plugin.util.ProgressMonitorAdapter@44899b
      basic: PluginMain.unregisterApplet: 1 from mananger sun.plugin2.applet.Applet2Manager@1e3aaf6
      security: --- parseCommandLine converted : -Xmx256m -Djnlp.packEnabled=true
      into:
      [-Xmx256m, -Djnlp.packEnabled=true]
      basic: Added progress listener: sun.plugin.util.ProgressMonitorAdapter@a205d2
      basic: Plugin2ClassLoader.addURL parent called for http://sgmac/workspaces/eclipse/Pack200%20Applet-Simple/testapplet.jar
      security: Validate the certificate chain using CertPath API
      security: SHA-256 finger print: 6BE7B7BB9E9DBCC0E168FC768727256F0DD54D97FF09172E3B592AE3347CE0D5
      security: SHA-256 finger print: AF840CA2B9DFB776BF81AA94C401BC440C52E5C590C43607A13D6680D83E3349
      security: SHA-256 finger print: 8D722F81A9C113C0791DF136A2966DB26C950A971DB46B4199F4EA54B78BFB9F
      security: The certificate hasnt been expired, no need to check timestamping info
      security: The CRL support is disabled
      security: The OCSP support is disabled
      security: This OCSP End Entity validation is disabled
      network: Created version ID: 1.7.0.21
      network: Created version ID: 1.7.0.21
      basic: Applet loaded.
      basic: Applet resized and added to parent container
      basic: PERF: AppletExecutionRunnable - applet.init() BEGIN ; jvmLaunch dt 329941 us, pluginInit dt 10840111 us, TotalTime: 11170052 us
      **** Content from text file in JAR (getResourceAsStream): Text file content
      network: Connecting http://sgmac/workspaces/eclipse/Pack200%20Applet-Simple/testapplet.jar.pack.gz.pack.gz with proxy=DIRECT
      network: Connecting http://sgmac:80/ with proxy=DIRECT
      network: Connecting http://sgmac/workspaces/eclipse/Pack200%20Applet-Simple/testapplet.jar.pack.gz.pack.gz with proxy=DIRECT
      network: Connecting http://sgmac:80/ with proxy=DIRECT
      network: Connecting http://sgmac/workspaces/eclipse/Pack200%20Applet-Simple/testapplet.jar.pack.gz with proxy=DIRECT
      network: ResponseCode for http://sgmac/workspaces/eclipse/Pack200%20Applet-Simple/testapplet.jar.pack.gz : 200
      network: Encoding for http://sgmac/workspaces/eclipse/Pack200%20Applet-Simple/testapplet.jar.pack.gz : null
      network: Server response: (length: 5132, lastModified: Fri May 03 16:28:51 CEST 2013, downloadVersion: null, mimeType: application/x-gzip)
      network: Downloading resource: http://sgmac/workspaces/eclipse/Pack200%20Applet-Simple/testapplet.jar.pack.gz
      Content-Length: 5.132
      Content-Encoding: null
      network: Disconnect connection to http://sgmac/workspaces/eclipse/Pack200%20Applet-Simple/testapplet.jar.pack.gz
      java.io.IOException: Invalid jar file
      at com.sun.deploy.net.HttpDownloadHelper.download(Unknown Source)
      at com.sun.deploy.net.DownloadEngine.downloadResourceToTempDir(Unknown Source)
      at com.sun.deploy.net.DownloadEngine.actionDownload(Unknown Source)
      at com.sun.deploy.net.DownloadEngine.downloadResource(Unknown Source)
      at com.sun.deploy.cache.ResourceProviderImpl.getResource(Unknown Source)
      at com.sun.deploy.cache.ResourceProviderImpl.getResource(Unknown Source)
      at sun.plugin.PluginURLJarFileCallBack$1.run(Unknown Source)
      at java.security.AccessController.doPrivileged(Native Method)
      at sun.plugin.PluginURLJarFileCallBack.retrieve(Unknown Source)
      at sun.net.www.protocol.jar.URLJarFile.retrieve(Unknown Source)
      at sun.net.www.protocol.jar.URLJarFile.getJarFile(Unknown Source)
      at sun.net.www.protocol.jar.JarFileFactory.get(Unknown Source)
      at sun.net.www.protocol.jar.JarURLConnection.connect(Unknown Source)
      at sun.plugin.net.protocol.jar.CachedJarURLConnection.connect(Unknown Source)
      at sun.plugin.net.protocol.jar.CachedJarURLConnection.getInputStream(Unknown Source)
      at java.net.URL.openStream(Unknown Source)
      at TestApplet.init(Unknown Source)
      at com.sun.deploy.uitoolkit.impl.awt.AWTAppletAdapter.init(Unknown Source)
      at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
      at java.lang.Thread.run(Unknown Source)
      com.sun.deploy.net.FailedDownloadException: Unable to load resource: http://sgmac/workspaces/eclipse/Pack200%20Applet-Simple/testapplet.jar.pack.gz
      at com.sun.deploy.net.DownloadEngine.actionDownload(Unknown Source)
      at com.sun.deploy.net.DownloadEngine.downloadResource(Unknown Source)
      at com.sun.deploy.cache.ResourceProviderImpl.getResource(Unknown Source)
      at com.sun.deploy.cache.ResourceProviderImpl.getResource(Unknown Source)
      at sun.plugin.PluginURLJarFileCallBack$1.run(Unknown Source)
      at java.security.AccessController.doPrivileged(Native Method)
      at sun.plugin.PluginURLJarFileCallBack.retrieve(Unknown Source)
      at sun.net.www.protocol.jar.URLJarFile.retrieve(Unknown Source)
      at sun.net.www.protocol.jar.URLJarFile.getJarFile(Unknown Source)
      at sun.net.www.protocol.jar.JarFileFactory.get(Unknown Source)
      at sun.net.www.protocol.jar.JarURLConnection.connect(Unknown Source)
      at sun.plugin.net.protocol.jar.CachedJarURLConnection.connect(Unknown Source)
      at sun.plugin.net.protocol.jar.CachedJarURLConnection.getInputStream(Unknown Source)
      at java.net.URL.openStream(Unknown Source)
      at TestApplet.init(Unknown Source)
      at com.sun.deploy.uitoolkit.impl.awt.AWTAppletAdapter.init(Unknown Source)
      at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
      at java.lang.Thread.run(Unknown Source)
      Caused by:
      java.io.IOException: Invalid jar file
      at com.sun.deploy.net.HttpDownloadHelper.download(Unknown Source)
      at com.sun.deploy.net.DownloadEngine.downloadResourceToTempDir(Unknown Source)
      at com.sun.deploy.net.DownloadEngine.actionDownload(Unknown Source)
      at com.sun.deploy.net.DownloadEngine.downloadResource(Unknown Source)
      at com.sun.deploy.cache.ResourceProviderImpl.getResource(Unknown Source)
      at com.sun.deploy.cache.ResourceProviderImpl.getResource(Unknown Source)
      at sun.plugin.PluginURLJarFileCallBack$1.run(Unknown Source)
      at java.security.AccessController.doPrivileged(Native Method)
      at sun.plugin.PluginURLJarFileCallBack.retrieve(Unknown Source)
      at sun.net.www.protocol.jar.URLJarFile.retrieve(Unknown Source)
      at sun.net.www.protocol.jar.URLJarFile.getJarFile(Unknown Source)
      at sun.net.www.protocol.jar.JarFileFactory.get(Unknown Source)
      at sun.net.www.protocol.jar.JarURLConnection.connect(Unknown Source)
      at sun.plugin.net.protocol.jar.CachedJarURLConnection.connect(Unknown Source)
      at sun.plugin.net.protocol.jar.CachedJarURLConnection.getInputStream(Unknown Source)
      at java.net.URL.openStream(Unknown Source)
      at TestApplet.init(Unknown Source)
      at com.sun.deploy.uitoolkit.impl.awt.AWTAppletAdapter.init(Unknown Source)
      at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
      at java.lang.Thread.run(Unknown Source)
      basic: Applet initialized
      basic: Starting applet
      basic: completed perf rollup
      basic: Applet made visible
      basic: Applet started
      basic: Told clients applet is started


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.io.BufferedReader;
      import java.io.IOException;
      import java.io.InputStream;
      import java.io.InputStreamReader;
      import java.net.URL;

      import javax.swing.JApplet;

      public class TestApplet extends JApplet {
          
          
          public void init() {
              try {
                  InputStream is = getClass().getResourceAsStream( " /test.txt " );
                  System.out.println( " **** Content from text file in JAR (getResourceAsStream): " +fromStream(is));
                  URL url = getClass().getResource( " /test.txt " );
                  System.out.println( " **** Content from text file in JAR (url.openStream(): " +fromStream(url.openStream()));
                  
              } catch (Exception e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
              }
          }
          
          public static String fromStream(InputStream in) throws IOException {
              BufferedReader reader = new BufferedReader(new InputStreamReader(in));
              StringBuilder out = new StringBuilder();
              String line;
              while ((line = reader.readLine()) != null) {
                  out.append(line);
              }
              return out.toString();
          }
      }
      ---------- END SOURCE ----------

        Attachments

          Activity

            People

            • Assignee:
              van Vivi An (Inactive)
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: