< prev index next >

src/java.base/share/classes/java/net/URLClassLoader.java

Print this page
rev 15821 : 8165271: Fix use of reflection to gain access to private fields
Reviewed-by:


 752      * @param urls the URLs to search for classes and resources
 753      * @exception  NullPointerException if {@code urls} is {@code null}.
 754      * @return the resulting class loader
 755      */
 756     public static URLClassLoader newInstance(final URL[] urls) {
 757         // Save the caller's context
 758         final AccessControlContext acc = AccessController.getContext();
 759         // Need a privileged block to create the class loader
 760         URLClassLoader ucl = AccessController.doPrivileged(
 761             new PrivilegedAction<>() {
 762                 public URLClassLoader run() {
 763                     return new FactoryURLClassLoader(urls, acc);
 764                 }
 765             });
 766         return ucl;
 767     }
 768 
 769     static {
 770         SharedSecrets.setJavaNetAccess(
 771             new JavaNetAccess() {

 772                 public URLClassPath getURLClassPath(URLClassLoader u) {
 773                     return u.ucp;
 774                 }





 775             }
 776         );
 777         ClassLoader.registerAsParallelCapable();
 778     }
 779 }
 780 
 781 final class FactoryURLClassLoader extends URLClassLoader {
 782 
 783     static {
 784         ClassLoader.registerAsParallelCapable();
 785     }
 786 
 787     FactoryURLClassLoader(URL[] urls, ClassLoader parent,
 788                           AccessControlContext acc) {
 789         super(urls, parent, acc);
 790     }
 791 
 792     FactoryURLClassLoader(URL[] urls, AccessControlContext acc) {
 793         super(urls, acc);
 794     }


 752      * @param urls the URLs to search for classes and resources
 753      * @exception  NullPointerException if {@code urls} is {@code null}.
 754      * @return the resulting class loader
 755      */
 756     public static URLClassLoader newInstance(final URL[] urls) {
 757         // Save the caller's context
 758         final AccessControlContext acc = AccessController.getContext();
 759         // Need a privileged block to create the class loader
 760         URLClassLoader ucl = AccessController.doPrivileged(
 761             new PrivilegedAction<>() {
 762                 public URLClassLoader run() {
 763                     return new FactoryURLClassLoader(urls, acc);
 764                 }
 765             });
 766         return ucl;
 767     }
 768 
 769     static {
 770         SharedSecrets.setJavaNetAccess(
 771             new JavaNetAccess() {
 772                 @Override
 773                 public URLClassPath getURLClassPath(URLClassLoader u) {
 774                     return u.ucp;
 775                 }
 776 
 777                 @Override
 778                 public AccessControlContext getAccessControlContext(URLClassLoader u) {
 779                     return u.acc;
 780                 }
 781             }
 782         );
 783         ClassLoader.registerAsParallelCapable();
 784     }
 785 }
 786 
 787 final class FactoryURLClassLoader extends URLClassLoader {
 788 
 789     static {
 790         ClassLoader.registerAsParallelCapable();
 791     }
 792 
 793     FactoryURLClassLoader(URL[] urls, ClassLoader parent,
 794                           AccessControlContext acc) {
 795         super(urls, parent, acc);
 796     }
 797 
 798     FactoryURLClassLoader(URL[] urls, AccessControlContext acc) {
 799         super(urls, acc);
 800     }
< prev index next >