changeset 14217:f7e100339605

Fix InternalError thrown by Class.forName
author mchung
date Mon, 12 Oct 2015 20:22:06 -0700
parents 2f2fa42c9342
children 515149589edb
files src/java.base/share/classes/java/lang/Class.java
diffstat 1 files changed, 7 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.base/share/classes/java/lang/Class.java	Sat Oct 10 15:44:26 2015 +0100
+++ b/src/java.base/share/classes/java/lang/Class.java	Mon Oct 12 20:22:06 2015 -0700
@@ -418,6 +418,10 @@
         Objects.requireNonNull(module);
         Objects.requireNonNull(name);
 
+        if (!module.isNamed()) {
+            throw new IllegalArgumentException(module.toString() + " is not a named module");
+        }
+
         SecurityManager sm = System.getSecurityManager();
         if (sm != null) {
             sm.checkPermission(SecurityConstants.GET_CLASSLOADER_PERMISSION);
@@ -432,10 +436,10 @@
         } else {
             c = cl.loadLocalClassOrNull(name);
         }
-        if (c != null && c.getModule() != module) {
-            throw new InternalError(c.getName() + " not in " + module);
+        if (c != null && c.getModule() == module) {
+            return c;
         }
-        return c;
+        return null;
     }
 
     /**