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

JarURLConnection.getJarFile throws Exception if some process is holding the file

    Details

    • Subcomponent:
    • CPU:
      x86_64
    • OS:
      windows_10

      Description

      ADDITIONAL SYSTEM INFORMATION :
      ・OS:
      Microsoft Windows [Version 10.0.17134.829]
      ・java -version:
      openjdk version "14-ea" 2020-03-17
      OpenJDK Runtime Environment (build 14-ea+19-824)
      OpenJDK 64-Bit Server VM (build 14-ea+19-824, mixed mode, sharing)

      A DESCRIPTION OF THE PROBLEM :
      Processes such as antivirus software may hold files for a short time.
      If the process holds a jar file, FileNotFoundException is thrown at
      JarURLConnection.getJarFile(), when accessing the file to get resource.
      Also, if the JDK tries to load a class file in a jar or module file held by the process,
      java.lang.NoClassDefFoundError is thrown at initial class loading.

      This can be fixed by retrying the access after a short sleep.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run test case.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      No Exception
      ACTUAL -
      Exception in thread "main" java.io.FileNotFoundException: C:\work\tmp\ZipException\tmp.jar (The process cannot access the file because it is being used by another process)
              at java.base/java.io.RandomAccessFile.open0(Native Method)
              at java.base/java.io.RandomAccessFile.open(RandomAccessFile.java:347)
              at java.base/java.io.RandomAccessFile.<init>(RandomAccessFile.java:261)
              at java.base/java.io.RandomAccessFile.<init>(RandomAccessFile.java:216)
              at java.base/java.util.zip.ZipFile$Source.<init>(ZipFile.java:1206)
              at java.base/java.util.zip.ZipFile$Source.get(ZipFile.java:1172)
              at java.base/java.util.zip.ZipFile$CleanableResource.<init>(ZipFile.java:719)
              at java.base/java.util.zip.ZipFile.<init>(ZipFile.java:239)
              at java.base/java.util.zip.ZipFile.<init>(ZipFile.java:169)
              at java.base/java.util.jar.JarFile.<init>(JarFile.java:346)
              at java.base/sun.net.www.protocol.jar.URLJarFile.&lt;init&gt;(URLJarFile.java:103)
              at java.base/sun.net.www.protocol.jar.URLJarFile.getJarFile(URLJarFile.java:72)
              at java.base/sun.net.www.protocol.jar.JarFileFactory.get(JarFileFactory.java:94)
              at java.base/sun.net.www.protocol.jar.JarURLConnection.connect(JarURLConnection.java:125)
              at java.base/sun.net.www.protocol.jar.JarURLConnection.getJarFile(JarURLConnection.java:92)
              at ZipExceptionTest.main(ZipExceptionTest.java:43)

      or

      Error occurred during initialization of VM
      java/lang/NoClassDefFoundError: java/lang/Object

      ---------- BEGIN SOURCE ----------
      I can send test case.
      ---------- END SOURCE ----------

      FREQUENCY : rarely


        Attachments

          Activity

            People

            • Assignee:
              bpb Brian Burkhalter
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated: