< prev index next >

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

Print this page
rev 51517 : 8205525: Improve exception messages during manifest parsing of jar archives


 400      *
 401      * @throws IllegalStateException
 402      *         may be thrown if the jar file has been closed
 403      * @throws IOException  if an I/O error has occurred
 404      */
 405     public Manifest getManifest() throws IOException {
 406         return getManifestFromReference();
 407     }
 408 
 409     private Manifest getManifestFromReference() throws IOException {
 410         Manifest man = manRef != null ? manRef.get() : null;
 411 
 412         if (man == null) {
 413 
 414             JarEntry manEntry = getManEntry();
 415 
 416             // If found then load the manifest
 417             if (manEntry != null) {
 418                 if (verify) {
 419                     byte[] b = getBytes(manEntry);
 420                     man = new Manifest(new ByteArrayInputStream(b));
 421                     if (!jvInitialized) {
 422                         jv = new JarVerifier(b);
 423                     }
 424                 } else {
 425                     man = new Manifest(super.getInputStream(manEntry));
 426                 }
 427                 manRef = new SoftReference<>(man);
 428             }
 429         }
 430         return man;
 431     }
 432 
 433     private String[] getMetaInfEntryNames() {
 434         return JUZFA.getMetaInfEntryNames((ZipFile)this);
 435     }
 436 
 437     /**
 438      * Returns the {@code JarEntry} for the given base entry name or
 439      * {@code null} if not found.
 440      *
 441      * <p>If this {@code JarFile} is a multi-release jar file and is configured
 442      * to be processed as such, then a search is performed to find and return
 443      * a {@code JarEntry} that is the latest versioned entry associated with the
 444      * given entry name.  The returned {@code JarEntry} is the versioned entry
 445      * corresponding to the given base entry name prefixed with the string




 400      *
 401      * @throws IllegalStateException
 402      *         may be thrown if the jar file has been closed
 403      * @throws IOException  if an I/O error has occurred
 404      */
 405     public Manifest getManifest() throws IOException {
 406         return getManifestFromReference();
 407     }
 408 
 409     private Manifest getManifestFromReference() throws IOException {
 410         Manifest man = manRef != null ? manRef.get() : null;
 411 
 412         if (man == null) {
 413 
 414             JarEntry manEntry = getManEntry();
 415 
 416             // If found then load the manifest
 417             if (manEntry != null) {
 418                 if (verify) {
 419                     byte[] b = getBytes(manEntry);
 420                     man = new Manifest(new ByteArrayInputStream(b), getName());
 421                     if (!jvInitialized) {
 422                         jv = new JarVerifier(b);
 423                     }
 424                 } else {
 425                     man = new Manifest(super.getInputStream(manEntry), getName());
 426                 }
 427                 manRef = new SoftReference<>(man);
 428             }
 429         }
 430         return man;
 431     }
 432 
 433     private String[] getMetaInfEntryNames() {
 434         return JUZFA.getMetaInfEntryNames((ZipFile)this);
 435     }
 436 
 437     /**
 438      * Returns the {@code JarEntry} for the given base entry name or
 439      * {@code null} if not found.
 440      *
 441      * <p>If this {@code JarFile} is a multi-release jar file and is configured
 442      * to be processed as such, then a search is performed to find and return
 443      * a {@code JarEntry} that is the latest versioned entry associated with the
 444      * given entry name.  The returned {@code JarEntry} is the versioned entry
 445      * corresponding to the given base entry name prefixed with the string


< prev index next >