< prev index next >

src/java.base/share/classes/java/util/jar/JarFile.java

Print this page
@@ -25,10 +25,11 @@
  
  package java.util.jar;
  
  import jdk.internal.access.SharedSecrets;
  import jdk.internal.access.JavaUtilZipFileAccess;
+ import jdk.internal.misc.Gate;
  import sun.security.action.GetPropertyAction;
  import sun.security.util.ManifestEntryVerifier;
  
  import java.io.ByteArrayInputStream;
  import java.io.EOFException;

@@ -148,11 +149,11 @@
      private static final Runtime.Version BASE_VERSION;
      private static final int BASE_VERSION_FEATURE;
      private static final Runtime.Version RUNTIME_VERSION;
      private static final boolean MULTI_RELEASE_ENABLED;
      private static final boolean MULTI_RELEASE_FORCED;
-     private static final ThreadLocal<Boolean> isInitializing = new ThreadLocal<>();
+     private static final Gate INITIALIZING_GATE = Gate.create();
      // The maximum size of array to allocate. Some VMs reserve some header words in an array.
      private static final int MAX_ARRAY_SIZE = Integer.MAX_VALUE - 8;
  
      private SoftReference<Manifest> manRef;
      private JarEntry manEntry;

@@ -1026,23 +1027,22 @@
              maybeInstantiateVerifier();
          } catch (IOException e) {
              throw new RuntimeException(e);
          }
          if (jv != null && !jvInitialized) {
-             isInitializing.set(Boolean.TRUE);
+             INITIALIZING_GATE.enter();
              try {
                  initializeVerifier();
                  jvInitialized = true;
              } finally {
-                 isInitializing.set(Boolean.FALSE);
+                 INITIALIZING_GATE.exit();
              }
          }
      }
  
      static boolean isInitializing() {
-         Boolean value = isInitializing.get();
-         return (value == null) ? false : value;
+         return INITIALIZING_GATE.inside();
      }
  
      /*
       * Returns a versioned {@code JarFileEntry} for the given entry,
       * if there is one. Otherwise returns the original entry. This
< prev index next >