jdk/src/share/classes/java/util/ServiceLoader.java
changeset 14229 40fbffe104bd
parent 14191 01f4a54604a6
parent 14228 131a42bc2c20
child 18777 cb1cc62972b8
--- a/jdk/src/share/classes/java/util/ServiceLoader.java	Tue Oct 23 09:41:52 2012 -0700
+++ b/jdk/src/share/classes/java/util/ServiceLoader.java	Tue Oct 23 11:29:53 2012 -0700
@@ -358,14 +358,21 @@
             }
             String cn = nextName;
             nextName = null;
+            Class<?> c = null;
             try {
-                S p = service.cast(Class.forName(cn, true, loader)
-                                   .newInstance());
-                providers.put(cn, p);
-                return p;
+                c = Class.forName(cn, false, loader);
             } catch (ClassNotFoundException x) {
                 fail(service,
                      "Provider " + cn + " not found");
+            }
+            if (!service.isAssignableFrom(c)) {
+                fail(service,
+                     "Provider " + cn  + " not a subtype");
+            }
+            try {
+                S p = service.cast(c.newInstance());
+                providers.put(cn, p);
+                return p;
             } catch (Throwable x) {
                 fail(service,
                      "Provider " + cn + " could not be instantiated: " + x,