jdk/src/java.base/share/classes/java/net/URLClassLoader.java
changeset 26214 2e116793d412
parent 26212 7585e2404b2a
parent 25859 3317bb8137f4
child 26487 605e2ffaec14
equal deleted inserted replaced
26195:64b54ed39429 26214:2e116793d412
     1 /*
     1 /*
     2  * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
   405             }
   405             }
   406         }
   406         }
   407         return pkg;
   407         return pkg;
   408     }
   408     }
   409 
   409 
       
   410     // Also called by VM to define Package for classes loaded from the CDS
       
   411     // archive
       
   412     private void definePackageInternal(String pkgname, Manifest man, URL url)
       
   413     {
       
   414         if (getAndVerifyPackage(pkgname, man, url) == null) {
       
   415             try {
       
   416                 if (man != null) {
       
   417                     definePackage(pkgname, man, url);
       
   418                 } else {
       
   419                     definePackage(pkgname, null, null, null, null, null, null, null);
       
   420                 }
       
   421             } catch (IllegalArgumentException iae) {
       
   422                 // parallel-capable class loaders: re-verify in case of a
       
   423                 // race condition
       
   424                 if (getAndVerifyPackage(pkgname, man, url) == null) {
       
   425                     // Should never happen
       
   426                     throw new AssertionError("Cannot find package " +
       
   427                                              pkgname);
       
   428                 }
       
   429             }
       
   430         }
       
   431     }
       
   432 
   410     /*
   433     /*
   411      * Defines a Class using the class bytes obtained from the specified
   434      * Defines a Class using the class bytes obtained from the specified
   412      * Resource. The resulting Class must be resolved before it can be
   435      * Resource. The resulting Class must be resolved before it can be
   413      * used.
   436      * used.
   414      */
   437      */
   418         URL url = res.getCodeSourceURL();
   441         URL url = res.getCodeSourceURL();
   419         if (i != -1) {
   442         if (i != -1) {
   420             String pkgname = name.substring(0, i);
   443             String pkgname = name.substring(0, i);
   421             // Check if package already loaded.
   444             // Check if package already loaded.
   422             Manifest man = res.getManifest();
   445             Manifest man = res.getManifest();
   423             if (getAndVerifyPackage(pkgname, man, url) == null) {
   446             definePackageInternal(pkgname, man, url);
   424                 try {
       
   425                     if (man != null) {
       
   426                         definePackage(pkgname, man, url);
       
   427                     } else {
       
   428                         definePackage(pkgname, null, null, null, null, null, null, null);
       
   429                     }
       
   430                 } catch (IllegalArgumentException iae) {
       
   431                     // parallel-capable class loaders: re-verify in case of a
       
   432                     // race condition
       
   433                     if (getAndVerifyPackage(pkgname, man, url) == null) {
       
   434                         // Should never happen
       
   435                         throw new AssertionError("Cannot find package " +
       
   436                                                  pkgname);
       
   437                     }
       
   438                 }
       
   439             }
       
   440         }
   447         }
   441         // Now read the class bytes and define the class
   448         // Now read the class bytes and define the class
   442         java.nio.ByteBuffer bb = res.getByteBuffer();
   449         java.nio.ByteBuffer bb = res.getByteBuffer();
   443         if (bb != null) {
   450         if (bb != null) {
   444             // Use (direct) ByteBuffer:
   451             // Use (direct) ByteBuffer: