--- a/jdk/src/java.base/share/classes/java/lang/Class.java Thu Feb 09 17:21:47 2017 +0000
+++ b/jdk/src/java.base/share/classes/java/lang/Class.java Fri Feb 10 09:04:39 2017 +0000
@@ -425,6 +425,7 @@
* </ul>
*
* @since 9
+ * @spec JPMS
*/
@CallerSensitive
public static Class<?> forName(Module module, String name) {
@@ -819,6 +820,7 @@
* @return the module that this class or interface is a member of
*
* @since 9
+ * @spec JPMS
*/
public Module getModule() {
return module;
@@ -924,6 +926,8 @@
* this method returns {@code null}.
*
* @return the package of this class.
+ * @revised 9
+ * @spec JPMS
*/
public Package getPackage() {
if (isPrimitive() || isArray()) {
@@ -951,20 +955,30 @@
* declaring class} of the {@link #getEnclosingMethod enclosing method} or
* {@link #getEnclosingConstructor enclosing constructor}.
*
- * <p> This method returns {@code null} if this class represents an array type,
- * a primitive type or void.
+ * <p> If this class represents an array type then this method returns the
+ * package name of the element type. If this class represents a primitive
+ * type or void then the package name "{@code java.lang}" is returned.
*
* @return the fully qualified package name
*
* @since 9
+ * @spec JPMS
* @jls 6.7 Fully Qualified Names
*/
public String getPackageName() {
String pn = this.packageName;
- if (pn == null && !isArray() && !isPrimitive()) {
- String cn = getName();
- int dot = cn.lastIndexOf('.');
- pn = (dot != -1) ? cn.substring(0, dot).intern() : "";
+ if (pn == null) {
+ Class<?> c = this;
+ while (c.isArray()) {
+ c = c.getComponentType();
+ }
+ if (c.isPrimitive()) {
+ pn = "java.lang";
+ } else {
+ String cn = c.getName();
+ int dot = cn.lastIndexOf('.');
+ pn = (dot != -1) ? cn.substring(0, dot).intern() : "";
+ }
this.packageName = pn;
}
return pn;
@@ -2491,10 +2505,16 @@
* Finds a resource with a given name.
*
* <p> If this class is in a named {@link Module Module} then this method
- * will attempt to find the resource in the module by means of the absolute
- * resource name, subject to the rules for encapsulation specified in the
- * {@code Module} {@link Module#getResourceAsStream getResourceAsStream}
- * method.
+ * will attempt to find the resource in the module. This is done by
+ * delegating to the module's class loader {@link
+ * ClassLoader#findResource(String,String) findResource(String,String)}
+ * method, invoking it with the module name and the absolute name of the
+ * resource. Resources in named modules are subject to the rules for
+ * encapsulation specified in the {@code Module} {@link
+ * Module#getResourceAsStream getResourceAsStream} method and so this
+ * method returns {@code null} when the resource is a
+ * non-"{@code .class}" resource in a package that is not open to the
+ * caller's module.
*
* <p> Otherwise, if this class is not in a named module then the rules for
* searching resources associated with a given class are implemented by the
@@ -2503,9 +2523,8 @@
* the bootstrap class loader, the method delegates to {@link
* ClassLoader#getSystemResourceAsStream}.
*
- * <p> Before finding a resource in the caller's module or delegation to a
- * class loader, an absolute resource name is constructed from the given
- * resource name using this algorithm:
+ * <p> Before delegation, an absolute resource name is constructed from the
+ * given resource name using this algorithm:
*
* <ul>
*
@@ -2532,7 +2551,11 @@
* least the caller module, or access to the resource is denied
* by the security manager.
* @throws NullPointerException If {@code name} is {@code null}
+ *
+ * @see Module#getResourceAsStream(String)
* @since 1.1
+ * @revised 9
+ * @spec JPMS
*/
@CallerSensitive
public InputStream getResourceAsStream(String name) {
@@ -2585,10 +2608,16 @@
* Finds a resource with a given name.
*
* <p> If this class is in a named {@link Module Module} then this method
- * will attempt to find the resource in the module by means of the absolute
- * resource name, subject to the rules for encapsulation specified in the
- * {@code Module} {@link Module#getResourceAsStream getResourceAsStream}
- * method.
+ * will attempt to find the resource in the module. This is done by
+ * delegating to the module's class loader {@link
+ * ClassLoader#findResource(String,String) findResource(String,String)}
+ * method, invoking it with the module name and the absolute name of the
+ * resource. Resources in named modules are subject to the rules for
+ * encapsulation specified in the {@code Module} {@link
+ * Module#getResourceAsStream getResourceAsStream} method and so this
+ * method returns {@code null} when the resource is a
+ * non-"{@code .class}" resource in a package that is not open to the
+ * caller's module.
*
* <p> Otherwise, if this class is not in a named module then the rules for
* searching resources associated with a given class are implemented by the
@@ -2627,6 +2656,8 @@
* manager.
* @throws NullPointerException If {@code name} is {@code null}
* @since 1.1
+ * @revised 9
+ * @spec JPMS
*/
@CallerSensitive
public URL getResource(String name) {