8140314: Verify IIOMetadataFormat class on loading
authorprr
Fri, 22 Jul 2016 15:57:57 -0700
changeset 40138 d294794a0878
parent 40137 0d7d50ab241f
child 40139 76f3dc8c0c28
8140314: Verify IIOMetadataFormat class on loading Reviewed-by: bpb
jdk/src/java.desktop/share/classes/javax/imageio/metadata/IIOMetadata.java
jdk/src/java.desktop/share/classes/javax/imageio/spi/ImageReaderWriterSpi.java
jdk/test/javax/imageio/plugins/external_plugin_tests/TestClassPathPlugin.sh
--- a/jdk/src/java.desktop/share/classes/javax/imageio/metadata/IIOMetadata.java	Fri Jul 22 14:32:49 2016 -0700
+++ b/jdk/src/java.desktop/share/classes/javax/imageio/metadata/IIOMetadata.java	Fri Jul 22 15:57:57 2016 -0700
@@ -414,14 +414,23 @@
         }
     }
 
+    // If updating this method also see the same in ImageReaderWriterSpi.java
     private Class<?> getMetadataFormatClass(String formatClassName) {
         Module thisModule = IIOMetadata.class.getModule();
         Module targetModule = this.getClass().getModule();
-        Class<?> c = Class.forName(targetModule, formatClassName);
+        Class<?> c = null;
+        try {
+            ClassLoader cl = this.getClass().getClassLoader();
+            c = Class.forName(formatClassName, false, cl);
+            if (!IIOMetadataFormat.class.isAssignableFrom(c)) {
+                return null;
+            }
+        } catch (ClassNotFoundException e) {
+        }
         if (thisModule.equals(targetModule) || c == null) {
             return c;
         }
-        if (thisModule.isNamed()) {
+        if (targetModule.isNamed()) {
             int i = formatClassName.lastIndexOf(".");
             String pn = i > 0 ? formatClassName.substring(0, i) : "";
             if (!targetModule.isExported(pn, thisModule)) {
--- a/jdk/src/java.desktop/share/classes/javax/imageio/spi/ImageReaderWriterSpi.java	Fri Jul 22 14:32:49 2016 -0700
+++ b/jdk/src/java.desktop/share/classes/javax/imageio/spi/ImageReaderWriterSpi.java	Fri Jul 22 15:57:57 2016 -0700
@@ -604,14 +604,23 @@
         }
     }
 
+    // If updating this method also see the same in IIOMetadata.java
     private Class<?> getMetadataFormatClass(String formatClassName) {
         Module thisModule = ImageReaderWriterSpi.class.getModule();
         Module targetModule = this.getClass().getModule();
-        Class<?> c = Class.forName(targetModule, formatClassName);
+        Class<?> c = null;
+        try {
+            ClassLoader cl = this.getClass().getClassLoader();
+            c = Class.forName(formatClassName, false, cl);
+            if (!IIOMetadataFormat.class.isAssignableFrom(c)) {
+                return null;
+            }
+        } catch (ClassNotFoundException e) {
+        }
         if (thisModule.equals(targetModule) || c == null) {
             return c;
         }
-        if (thisModule.isNamed()) {
+        if (targetModule.isNamed()) {
             int i = formatClassName.lastIndexOf(".");
             String pn = i > 0 ? formatClassName.substring(0, i) : "";
             if (!targetModule.isExported(pn, thisModule)) {
--- a/jdk/test/javax/imageio/plugins/external_plugin_tests/TestClassPathPlugin.sh	Fri Jul 22 14:32:49 2016 -0700
+++ b/jdk/test/javax/imageio/plugins/external_plugin_tests/TestClassPathPlugin.sh	Fri Jul 22 15:57:57 2016 -0700
@@ -22,7 +22,7 @@
 #
 
 # @test
-# @bug 8081729
+# @bug 8081729 8140314
 # @summary Test external plugin as classpath jar and as a modular jar.
 #          Test both cases with and without a security manager.