diff --git a/jdk/src/java.desktop/share/classes/javax/imageio/metadata/IIOMetadata.java b/jdk/src/java.desktop/share/classes/javax/imageio/metadata/IIOMetadata.java index 76e28bc9743..c9ac7374a00 100644 --- a/jdk/src/java.desktop/share/classes/javax/imageio/metadata/IIOMetadata.java +++ b/jdk/src/java.desktop/share/classes/javax/imageio/metadata/IIOMetadata.java @@ -414,14 +414,23 @@ public abstract class IIOMetadata { } } + // 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)) { diff --git a/jdk/src/java.desktop/share/classes/javax/imageio/spi/ImageReaderWriterSpi.java b/jdk/src/java.desktop/share/classes/javax/imageio/spi/ImageReaderWriterSpi.java index d46711aedc7..e5961b90e4a 100644 --- a/jdk/src/java.desktop/share/classes/javax/imageio/spi/ImageReaderWriterSpi.java +++ b/jdk/src/java.desktop/share/classes/javax/imageio/spi/ImageReaderWriterSpi.java @@ -604,14 +604,23 @@ public abstract class ImageReaderWriterSpi extends IIOServiceProvider { } } + // 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)) { diff --git a/jdk/test/javax/imageio/plugins/external_plugin_tests/TestClassPathPlugin.sh b/jdk/test/javax/imageio/plugins/external_plugin_tests/TestClassPathPlugin.sh index 196189a0c42..60e8fc04b2a 100644 --- a/jdk/test/javax/imageio/plugins/external_plugin_tests/TestClassPathPlugin.sh +++ b/jdk/test/javax/imageio/plugins/external_plugin_tests/TestClassPathPlugin.sh @@ -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.