You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by pn...@apache.org on 2020/01/21 12:14:20 UTC
[flink] 01/02: [FLINK-15355][plugins] PluginLoader allows access to
JDK9 modules.
This is an automated email from the ASF dual-hosted git repository.
pnowojski pushed a commit to branch release-1.10
in repository https://gitbox.apache.org/repos/asf/flink.git
commit 2d2e89c9bec59996b3c771e7158ce94e252c34a6
Author: Arvid Heise <ar...@ververica.com>
AuthorDate: Fri Jan 17 13:50:19 2020 +0100
[FLINK-15355][plugins] PluginLoader allows access to JDK9 modules.
With Java9, classes that have moved to modules are not accessible through the bootstrap classloader anymore. The platform classloader is the equivalent to the Java8 bootstrap classloader and now used for plugins.
---
.../org/apache/flink/core/plugin/PluginLoader.java | 19 ++++++++++++++++++-
1 file changed, 18 insertions(+), 1 deletion(-)
diff --git a/flink-core/src/main/java/org/apache/flink/core/plugin/PluginLoader.java b/flink-core/src/main/java/org/apache/flink/core/plugin/PluginLoader.java
index 94f04a3..b11fb3a 100644
--- a/flink-core/src/main/java/org/apache/flink/core/plugin/PluginLoader.java
+++ b/flink-core/src/main/java/org/apache/flink/core/plugin/PluginLoader.java
@@ -112,6 +112,8 @@ public class PluginLoader {
* starting with a whitelist prefix.
*/
private static final class PluginClassLoader extends URLClassLoader {
+ private static final ClassLoader PLATFORM_OR_BOOTSTRAP_LOADER;
+
private final ClassLoader flinkClassLoader;
private final String[] allowedFlinkPackages;
@@ -119,7 +121,7 @@ public class PluginLoader {
private final String[] allowedResourcePrefixes;
PluginClassLoader(URL[] pluginResourceURLs, ClassLoader flinkClassLoader, String[] allowedFlinkPackages) {
- super(pluginResourceURLs, null);
+ super(pluginResourceURLs, PLATFORM_OR_BOOTSTRAP_LOADER);
this.flinkClassLoader = flinkClassLoader;
this.allowedFlinkPackages = allowedFlinkPackages;
allowedResourcePrefixes = Arrays.stream(allowedFlinkPackages)
@@ -182,5 +184,20 @@ public class PluginLoader {
private boolean isAllowedFlinkResource(final String name) {
return Arrays.stream(allowedResourcePrefixes).anyMatch(name::startsWith);
}
+
+ static {
+ ClassLoader platformLoader = null;
+ try {
+ platformLoader = (ClassLoader) ClassLoader.class
+ .getMethod("getPlatformClassLoader")
+ .invoke(null);
+ } catch (NoSuchMethodException e) {
+ // on Java 8 this method does not exist, but using null indicates the bootstrap loader that we want
+ // to have
+ } catch (Exception e) {
+ throw new IllegalStateException("Cannot retrieve platform classloader on Java 9+", e);
+ }
+ PLATFORM_OR_BOOTSTRAP_LOADER = platformLoader;
+ }
}
}