jdk/src/share/classes/java/lang/ClassLoader.java
changeset 18776 c17100862d86
parent 18156 edb590d448c5
child 20782 2711da7ccd30
child 20831 96cf18811858
equal deleted inserted replaced
18775:fa61a37ed42b 18776:c17100862d86
   155  *              . . .
   155  *              . . .
   156  *         }
   156  *         }
   157  *     }
   157  *     }
   158  * </pre></blockquote>
   158  * </pre></blockquote>
   159  *
   159  *
   160  * <h4> <a name="name">Binary names</a> </h4>
   160  * <h3> <a name="name">Binary names</a> </h3>
   161  *
   161  *
   162  * <p> Any class name provided as a {@link String} parameter to methods in
   162  * <p> Any class name provided as a {@link String} parameter to methods in
   163  * <tt>ClassLoader</tt> must be a binary name as defined by
   163  * <tt>ClassLoader</tt> must be a binary name as defined by
   164  * <cite>The Java&trade; Language Specification</cite>.
   164  * <cite>The Java&trade; Language Specification</cite>.
   165  *
   165  *
   340      * Loads the class with the specified <a href="#name">binary name</a>.
   340      * Loads the class with the specified <a href="#name">binary name</a>.
   341      * This method searches for classes in the same manner as the {@link
   341      * This method searches for classes in the same manner as the {@link
   342      * #loadClass(String, boolean)} method.  It is invoked by the Java virtual
   342      * #loadClass(String, boolean)} method.  It is invoked by the Java virtual
   343      * machine to resolve class references.  Invoking this method is equivalent
   343      * machine to resolve class references.  Invoking this method is equivalent
   344      * to invoking {@link #loadClass(String, boolean) <tt>loadClass(name,
   344      * to invoking {@link #loadClass(String, boolean) <tt>loadClass(name,
   345      * false)</tt>}.  </p>
   345      * false)</tt>}.
   346      *
   346      *
   347      * @param  name
   347      * @param  name
   348      *         The <a href="#name">binary name</a> of the class
   348      *         The <a href="#name">binary name</a> of the class
   349      *
   349      *
   350      * @return  The resulting <tt>Class</tt> object
   350      * @return  The resulting <tt>Class</tt> object
   439      * Returns the lock object for class loading operations.
   439      * Returns the lock object for class loading operations.
   440      * For backward compatibility, the default implementation of this method
   440      * For backward compatibility, the default implementation of this method
   441      * behaves as follows. If this ClassLoader object is registered as
   441      * behaves as follows. If this ClassLoader object is registered as
   442      * parallel capable, the method returns a dedicated object associated
   442      * parallel capable, the method returns a dedicated object associated
   443      * with the specified class name. Otherwise, the method returns this
   443      * with the specified class name. Otherwise, the method returns this
   444      * ClassLoader object. </p>
   444      * ClassLoader object.
   445      *
   445      *
   446      * @param  className
   446      * @param  className
   447      *         The name of the to-be-loaded class
   447      *         The name of the to-be-loaded class
   448      *
   448      *
   449      * @return the lock for class loading operations
   449      * @return the lock for class loading operations
   504      * Finds the class with the specified <a href="#name">binary name</a>.
   504      * Finds the class with the specified <a href="#name">binary name</a>.
   505      * This method should be overridden by class loader implementations that
   505      * This method should be overridden by class loader implementations that
   506      * follow the delegation model for loading classes, and will be invoked by
   506      * follow the delegation model for loading classes, and will be invoked by
   507      * the {@link #loadClass <tt>loadClass</tt>} method after checking the
   507      * the {@link #loadClass <tt>loadClass</tt>} method after checking the
   508      * parent class loader for the requested class.  The default implementation
   508      * parent class loader for the requested class.  The default implementation
   509      * throws a <tt>ClassNotFoundException</tt>.  </p>
   509      * throws a <tt>ClassNotFoundException</tt>.
   510      *
   510      *
   511      * @param  name
   511      * @param  name
   512      *         The <a href="#name">binary name</a> of the class
   512      *         The <a href="#name">binary name</a> of the class
   513      *
   513      *
   514      * @return  The resulting <tt>Class</tt> object
   514      * @return  The resulting <tt>Class</tt> object
   770      * <p> An invocation of this method of the form
   770      * <p> An invocation of this method of the form
   771      * <i>cl</i><tt>.defineClass(</tt><i>name</i><tt>,</tt>
   771      * <i>cl</i><tt>.defineClass(</tt><i>name</i><tt>,</tt>
   772      * <i>bBuffer</i><tt>,</tt> <i>pd</i><tt>)</tt> yields exactly the same
   772      * <i>bBuffer</i><tt>,</tt> <i>pd</i><tt>)</tt> yields exactly the same
   773      * result as the statements
   773      * result as the statements
   774      *
   774      *
   775      * <blockquote><tt>
   775      *<p> <tt>
   776      * ...<br>
   776      * ...<br>
   777      * byte[] temp = new byte[</tt><i>bBuffer</i><tt>.{@link
   777      * byte[] temp = new byte[bBuffer.{@link
   778      * java.nio.ByteBuffer#remaining remaining}()];<br>
   778      * java.nio.ByteBuffer#remaining remaining}()];<br>
   779      *     </tt><i>bBuffer</i><tt>.{@link java.nio.ByteBuffer#get(byte[])
   779      *     bBuffer.{@link java.nio.ByteBuffer#get(byte[])
   780      * get}(temp);<br>
   780      * get}(temp);<br>
   781      *     return {@link #defineClass(String, byte[], int, int, ProtectionDomain)
   781      *     return {@link #defineClass(String, byte[], int, int, ProtectionDomain)
   782      * </tt><i>cl</i><tt>.defineClass}(</tt><i>name</i><tt>, temp, 0,
   782      * cl.defineClass}(name, temp, 0,
   783      * temp.length, </tt><i>pd</i><tt>);<br>
   783      * temp.length, pd);<br>
   784      * </tt></blockquote>
   784      * </tt></p>
   785      *
   785      *
   786      * @param  name
   786      * @param  name
   787      *         The expected <a href="#name">binary name</a>. of the class, or
   787      *         The expected <a href="#name">binary name</a>. of the class, or
   788      *         <tt>null</tt> if not known
   788      *         <tt>null</tt> if not known
   789      *
   789      *
   938      * Links the specified class.  This (misleadingly named) method may be
   938      * Links the specified class.  This (misleadingly named) method may be
   939      * used by a class loader to link a class.  If the class <tt>c</tt> has
   939      * used by a class loader to link a class.  If the class <tt>c</tt> has
   940      * already been linked, then this method simply returns. Otherwise, the
   940      * already been linked, then this method simply returns. Otherwise, the
   941      * class is linked as described in the "Execution" chapter of
   941      * class is linked as described in the "Execution" chapter of
   942      * <cite>The Java&trade; Language Specification</cite>.
   942      * <cite>The Java&trade; Language Specification</cite>.
   943      * </p>
       
   944      *
   943      *
   945      * @param  c
   944      * @param  c
   946      *         The class to link
   945      *         The class to link
   947      *
   946      *
   948      * @throws  NullPointerException
   947      * @throws  NullPointerException
  1010 
  1009 
  1011     /**
  1010     /**
  1012      * Returns the class with the given <a href="#name">binary name</a> if this
  1011      * Returns the class with the given <a href="#name">binary name</a> if this
  1013      * loader has been recorded by the Java virtual machine as an initiating
  1012      * loader has been recorded by the Java virtual machine as an initiating
  1014      * loader of a class with that <a href="#name">binary name</a>.  Otherwise
  1013      * loader of a class with that <a href="#name">binary name</a>.  Otherwise
  1015      * <tt>null</tt> is returned.  </p>
  1014      * <tt>null</tt> is returned.
  1016      *
  1015      *
  1017      * @param  name
  1016      * @param  name
  1018      *         The <a href="#name">binary name</a> of the class
  1017      *         The <a href="#name">binary name</a> of the class
  1019      *
  1018      *
  1020      * @return  The <tt>Class</tt> object, or <tt>null</tt> if the class has
  1019      * @return  The <tt>Class</tt> object, or <tt>null</tt> if the class has
  1030 
  1029 
  1031     private native final Class<?> findLoadedClass0(String name);
  1030     private native final Class<?> findLoadedClass0(String name);
  1032 
  1031 
  1033     /**
  1032     /**
  1034      * Sets the signers of a class.  This should be invoked after defining a
  1033      * Sets the signers of a class.  This should be invoked after defining a
  1035      * class.  </p>
  1034      * class.
  1036      *
  1035      *
  1037      * @param  c
  1036      * @param  c
  1038      *         The <tt>Class</tt> object
  1037      *         The <tt>Class</tt> object
  1039      *
  1038      *
  1040      * @param  signers
  1039      * @param  signers
  1123         return new CompoundEnumeration<>(tmp);
  1122         return new CompoundEnumeration<>(tmp);
  1124     }
  1123     }
  1125 
  1124 
  1126     /**
  1125     /**
  1127      * Finds the resource with the given name. Class loader implementations
  1126      * Finds the resource with the given name. Class loader implementations
  1128      * should override this method to specify where to find resources.  </p>
  1127      * should override this method to specify where to find resources.
  1129      *
  1128      *
  1130      * @param  name
  1129      * @param  name
  1131      *         The resource name
  1130      *         The resource name
  1132      *
  1131      *
  1133      * @return  A <tt>URL</tt> object for reading the resource, or
  1132      * @return  A <tt>URL</tt> object for reading the resource, or
  1141 
  1140 
  1142     /**
  1141     /**
  1143      * Returns an enumeration of {@link java.net.URL <tt>URL</tt>} objects
  1142      * Returns an enumeration of {@link java.net.URL <tt>URL</tt>} objects
  1144      * representing all the resources with the given name. Class loader
  1143      * representing all the resources with the given name. Class loader
  1145      * implementations should override this method to specify where to load
  1144      * implementations should override this method to specify where to load
  1146      * resources from.  </p>
  1145      * resources from.
  1147      *
  1146      *
  1148      * @param  name
  1147      * @param  name
  1149      *         The resource name
  1148      *         The resource name
  1150      *
  1149      *
  1151      * @return  An enumeration of {@link java.net.URL <tt>URL</tt>} objects for
  1150      * @return  An enumeration of {@link java.net.URL <tt>URL</tt>} objects for
  1159     protected Enumeration<URL> findResources(String name) throws IOException {
  1158     protected Enumeration<URL> findResources(String name) throws IOException {
  1160         return java.util.Collections.emptyEnumeration();
  1159         return java.util.Collections.emptyEnumeration();
  1161     }
  1160     }
  1162 
  1161 
  1163     /**
  1162     /**
  1164      * Registers the caller as parallel capable.</p>
  1163      * Registers the caller as parallel capable.
  1165      * The registration succeeds if and only if all of the following
  1164      * The registration succeeds if and only if all of the following
  1166      * conditions are met: <br>
  1165      * conditions are met:
  1167      * 1. no instance of the caller has been created</p>
  1166      * <ol>
  1168      * 2. all of the super classes (except class Object) of the caller are
  1167      * <li> no instance of the caller has been created</li>
  1169      * registered as parallel capable</p>
  1168      * <li> all of the super classes (except class Object) of the caller are
  1170      * Note that once a class loader is registered as parallel capable, there
  1169      * registered as parallel capable</li>
  1171      * is no way to change it back. </p>
  1170      * </ol>
       
  1171      * <p>Note that once a class loader is registered as parallel capable, there
       
  1172      * is no way to change it back.</p>
  1172      *
  1173      *
  1173      * @return  true if the caller is successfully registered as
  1174      * @return  true if the caller is successfully registered as
  1174      *          parallel capable and false if otherwise.
  1175      *          parallel capable and false if otherwise.
  1175      *
  1176      *
  1176      * @since   1.7
  1177      * @since   1.7
  1183     }
  1184     }
  1184 
  1185 
  1185     /**
  1186     /**
  1186      * Find a resource of the specified name from the search path used to load
  1187      * Find a resource of the specified name from the search path used to load
  1187      * classes.  This method locates the resource through the system class
  1188      * classes.  This method locates the resource through the system class
  1188      * loader (see {@link #getSystemClassLoader()}).  </p>
  1189      * loader (see {@link #getSystemClassLoader()}).
  1189      *
  1190      *
  1190      * @param  name
  1191      * @param  name
  1191      *         The resource name
  1192      *         The resource name
  1192      *
  1193      *
  1193      * @return  A {@link java.net.URL <tt>URL</tt>} object for reading the
  1194      * @return  A {@link java.net.URL <tt>URL</tt>} object for reading the
  1290     }
  1291     }
  1291 
  1292 
  1292     /**
  1293     /**
  1293      * Open for reading, a resource of the specified name from the search path
  1294      * Open for reading, a resource of the specified name from the search path
  1294      * used to load classes.  This method locates the resource through the
  1295      * used to load classes.  This method locates the resource through the
  1295      * system class loader (see {@link #getSystemClassLoader()}).  </p>
  1296      * system class loader (see {@link #getSystemClassLoader()}).
  1296      *
  1297      *
  1297      * @param  name
  1298      * @param  name
  1298      *         The resource name
  1299      *         The resource name
  1299      *
  1300      *
  1300      * @return  An input stream for reading the resource, or <tt>null</tt>
  1301      * @return  An input stream for reading the resource, or <tt>null</tt>
  1513     /**
  1514     /**
  1514      * Defines a package by name in this <tt>ClassLoader</tt>.  This allows
  1515      * Defines a package by name in this <tt>ClassLoader</tt>.  This allows
  1515      * class loaders to define the packages for their classes. Packages must
  1516      * class loaders to define the packages for their classes. Packages must
  1516      * be created before the class is defined, and package names must be
  1517      * be created before the class is defined, and package names must be
  1517      * unique within a class loader and cannot be redefined or changed once
  1518      * unique within a class loader and cannot be redefined or changed once
  1518      * created.  </p>
  1519      * created.
  1519      *
  1520      *
  1520      * @param  name
  1521      * @param  name
  1521      *         The package name
  1522      *         The package name
  1522      *
  1523      *
  1523      * @param  specTitle
  1524      * @param  specTitle
  1570         }
  1571         }
  1571     }
  1572     }
  1572 
  1573 
  1573     /**
  1574     /**
  1574      * Returns a <tt>Package</tt> that has been defined by this class loader
  1575      * Returns a <tt>Package</tt> that has been defined by this class loader
  1575      * or any of its ancestors.  </p>
  1576      * or any of its ancestors.
  1576      *
  1577      *
  1577      * @param  name
  1578      * @param  name
  1578      *         The package name
  1579      *         The package name
  1579      *
  1580      *
  1580      * @return  The <tt>Package</tt> corresponding to the given name, or
  1581      * @return  The <tt>Package</tt> corresponding to the given name, or
  1607         return pkg;
  1608         return pkg;
  1608     }
  1609     }
  1609 
  1610 
  1610     /**
  1611     /**
  1611      * Returns all of the <tt>Packages</tt> defined by this class loader and
  1612      * Returns all of the <tt>Packages</tt> defined by this class loader and
  1612      * its ancestors.  </p>
  1613      * its ancestors.
  1613      *
  1614      *
  1614      * @return  The array of <tt>Package</tt> objects defined by this
  1615      * @return  The array of <tt>Package</tt> objects defined by this
  1615      *          <tt>ClassLoader</tt>
  1616      *          <tt>ClassLoader</tt>
  1616      *
  1617      *
  1617      * @since  1.2
  1618      * @since  1.2
  1644     /**
  1645     /**
  1645      * Returns the absolute path name of a native library.  The VM invokes this
  1646      * Returns the absolute path name of a native library.  The VM invokes this
  1646      * method to locate the native libraries that belong to classes loaded with
  1647      * method to locate the native libraries that belong to classes loaded with
  1647      * this class loader. If this method returns <tt>null</tt>, the VM
  1648      * this class loader. If this method returns <tt>null</tt>, the VM
  1648      * searches the library along the path specified as the
  1649      * searches the library along the path specified as the
  1649      * "<tt>java.library.path</tt>" property.  </p>
  1650      * "<tt>java.library.path</tt>" property.
  1650      *
  1651      *
  1651      * @param  libname
  1652      * @param  libname
  1652      *         The library name
  1653      *         The library name
  1653      *
  1654      *
  1654      * @return  The absolute path of the native library
  1655      * @return  The absolute path of the native library
  1964      * Sets the default assertion status for this class loader.  This setting
  1965      * Sets the default assertion status for this class loader.  This setting
  1965      * determines whether classes loaded by this class loader and initialized
  1966      * determines whether classes loaded by this class loader and initialized
  1966      * in the future will have assertions enabled or disabled by default.
  1967      * in the future will have assertions enabled or disabled by default.
  1967      * This setting may be overridden on a per-package or per-class basis by
  1968      * This setting may be overridden on a per-package or per-class basis by
  1968      * invoking {@link #setPackageAssertionStatus(String, boolean)} or {@link
  1969      * invoking {@link #setPackageAssertionStatus(String, boolean)} or {@link
  1969      * #setClassAssertionStatus(String, boolean)}.  </p>
  1970      * #setClassAssertionStatus(String, boolean)}.
  1970      *
  1971      *
  1971      * @param  enabled
  1972      * @param  enabled
  1972      *         <tt>true</tt> if classes loaded by this class loader will
  1973      *         <tt>true</tt> if classes loaded by this class loader will
  1973      *         henceforth have assertions enabled by default, <tt>false</tt>
  1974      *         henceforth have assertions enabled by default, <tt>false</tt>
  1974      *         if they will have assertions disabled by default.
  1975      *         if they will have assertions disabled by default.
  2066      * Sets the default assertion status for this class loader to
  2067      * Sets the default assertion status for this class loader to
  2067      * <tt>false</tt> and discards any package defaults or class assertion
  2068      * <tt>false</tt> and discards any package defaults or class assertion
  2068      * status settings associated with the class loader.  This method is
  2069      * status settings associated with the class loader.  This method is
  2069      * provided so that class loaders can be made to ignore any command line or
  2070      * provided so that class loaders can be made to ignore any command line or
  2070      * persistent assertion status settings and "start with a clean slate."
  2071      * persistent assertion status settings and "start with a clean slate."
  2071      * </p>
       
  2072      *
  2072      *
  2073      * @since  1.4
  2073      * @since  1.4
  2074      */
  2074      */
  2075     public void clearAssertionStatus() {
  2075     public void clearAssertionStatus() {
  2076         /*
  2076         /*