141 private JarVerifier jv;
142 private boolean jvInitialized;
143 private boolean verify;
144 private final int version;
145 private boolean notVersioned;
146 private final boolean runtimeVersioned;
147
148 // indicates if Class-Path attribute present (only valid if hasCheckedSpecialAttributes true)
149 private boolean hasClassPathAttribute;
150 // true if manifest checked for special attributes
151 private volatile boolean hasCheckedSpecialAttributes;
152
153 static {
154 // Set up JavaUtilJarAccess in SharedSecrets
155 SharedSecrets.setJavaUtilJarAccess(new JavaUtilJarAccessImpl());
156
157 BASE_VERSION = 8; // one less than lowest version for versioned entries
158 RUNTIME_VERSION = AccessController.doPrivileged(
159 new PrivilegedAction<Integer>() {
160 public Integer run() {
161 Integer v = sun.misc.Version.jdkMajorVersion(); // fixme when JEP 223 Version integrated
162 Integer i = Integer.getInteger("jdk.util.jar.version", v);
163 i = i < 0 ? 0 : i;
164 return i > v ? v : i;
165 }
166 }
167 );
168 String multi_release = AccessController.doPrivileged(
169 new PrivilegedAction<String>() {
170 public String run() {
171 return System.getProperty("jdk.util.jar.enableMultiRelease", "true");
172 }
173 }
174 );
175 switch (multi_release) {
176 case "true":
177 default:
178 MULTI_RELEASE_ENABLED = true;
179 MULTI_RELEASE_FORCED = false;
180 break;
181 case "false":
342 * @param version specifies the release version for a multi-release jar file
343 * @throws IOException if an I/O error has occurred
344 * @throws IllegalArgumentException
345 * if the {@code mode} argument is invalid
346 * @throws SecurityException if access to the file is denied
347 * by the SecurityManager
348 * @throws NullPointerException if {@code version} is {@code null}
349 * @since 9
350 */
351 public JarFile(File file, boolean verify, int mode, Release version) throws IOException {
352 super(file, mode);
353 Objects.requireNonNull(version);
354 this.verify = verify;
355 // version applies to multi-release jar files, ignored for regular jar files
356 this.version = MULTI_RELEASE_FORCED ? RUNTIME_VERSION : version.value();
357 this.runtimeVersioned = version == Release.RUNTIME;
358 assert runtimeVersionExists();
359 }
360
361 private boolean runtimeVersionExists() {
362 int version = sun.misc.Version.jdkMajorVersion(); // fixme when JEP 223 integrated
363 try {
364 Release.valueOf(version);
365 return true;
366 } catch (IllegalArgumentException x) {
367 System.err.println("No JarFile.Release object for release " + version);
368 return false;
369 }
370 }
371
372 /**
373 * Returns the maximum version used when searching for versioned entries.
374 *
375 * @return the maximum version, or {@code Release.BASE} if this jar file is
376 * processed as if it is an unversioned jar file or is not a
377 * multi-release jar file
378 * @since 9
379 */
380 public final Release getVersion() {
381 if (isMultiRelease()) {
382 return runtimeVersioned ? Release.RUNTIME : Release.valueOf(version);
|
141 private JarVerifier jv;
142 private boolean jvInitialized;
143 private boolean verify;
144 private final int version;
145 private boolean notVersioned;
146 private final boolean runtimeVersioned;
147
148 // indicates if Class-Path attribute present (only valid if hasCheckedSpecialAttributes true)
149 private boolean hasClassPathAttribute;
150 // true if manifest checked for special attributes
151 private volatile boolean hasCheckedSpecialAttributes;
152
153 static {
154 // Set up JavaUtilJarAccess in SharedSecrets
155 SharedSecrets.setJavaUtilJarAccess(new JavaUtilJarAccessImpl());
156
157 BASE_VERSION = 8; // one less than lowest version for versioned entries
158 RUNTIME_VERSION = AccessController.doPrivileged(
159 new PrivilegedAction<Integer>() {
160 public Integer run() {
161 Integer v = jdk.Version.current().major();
162 Integer i = Integer.getInteger("jdk.util.jar.version", v);
163 i = i < 0 ? 0 : i;
164 return i > v ? v : i;
165 }
166 }
167 );
168 String multi_release = AccessController.doPrivileged(
169 new PrivilegedAction<String>() {
170 public String run() {
171 return System.getProperty("jdk.util.jar.enableMultiRelease", "true");
172 }
173 }
174 );
175 switch (multi_release) {
176 case "true":
177 default:
178 MULTI_RELEASE_ENABLED = true;
179 MULTI_RELEASE_FORCED = false;
180 break;
181 case "false":
342 * @param version specifies the release version for a multi-release jar file
343 * @throws IOException if an I/O error has occurred
344 * @throws IllegalArgumentException
345 * if the {@code mode} argument is invalid
346 * @throws SecurityException if access to the file is denied
347 * by the SecurityManager
348 * @throws NullPointerException if {@code version} is {@code null}
349 * @since 9
350 */
351 public JarFile(File file, boolean verify, int mode, Release version) throws IOException {
352 super(file, mode);
353 Objects.requireNonNull(version);
354 this.verify = verify;
355 // version applies to multi-release jar files, ignored for regular jar files
356 this.version = MULTI_RELEASE_FORCED ? RUNTIME_VERSION : version.value();
357 this.runtimeVersioned = version == Release.RUNTIME;
358 assert runtimeVersionExists();
359 }
360
361 private boolean runtimeVersionExists() {
362 int version = jdk.Version.current().major();
363 try {
364 Release.valueOf(version);
365 return true;
366 } catch (IllegalArgumentException x) {
367 System.err.println("No JarFile.Release object for release " + version);
368 return false;
369 }
370 }
371
372 /**
373 * Returns the maximum version used when searching for versioned entries.
374 *
375 * @return the maximum version, or {@code Release.BASE} if this jar file is
376 * processed as if it is an unversioned jar file or is not a
377 * multi-release jar file
378 * @since 9
379 */
380 public final Release getVersion() {
381 if (isMultiRelease()) {
382 return runtimeVersioned ? Release.RUNTIME : Release.valueOf(version);
|