Make ExtendedGroovyClassLoader compatible with Java 9

Closes gh-10445
This commit is contained in:
Andy Wilkinson 2017-09-28 17:38:05 +01:00
parent bec2e97b95
commit ebf3b47305
2 changed files with 12 additions and 3 deletions

View File

@ -175,7 +175,8 @@ public class ExtendedGroovyClassLoader extends GroovyClassLoader {
DefaultScopeParentClassLoader(ClassLoader parent) {
super(parent);
this.groovyOnlyClassLoader = new URLClassLoader(getGroovyJars(parent), null);
this.groovyOnlyClassLoader = new URLClassLoader(getGroovyJars(parent),
parent.getParent());
}
private URL[] getGroovyJars(final ClassLoader parent) {
@ -232,7 +233,9 @@ public class ExtendedGroovyClassLoader extends GroovyClassLoader {
@Override
protected Class<?> loadClass(String name, boolean resolve)
throws ClassNotFoundException {
this.groovyOnlyClassLoader.loadClass(name);
if (!name.startsWith("java.")) {
this.groovyOnlyClassLoader.loadClass(name);
}
return super.loadClass(name, resolve);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2016 the original author or authors.
* Copyright 2012-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -64,4 +64,10 @@ public class ExtendedGroovyClassLoaderTests {
this.defaultScopeGroovyClassLoader.loadClass("java.lang.Boolean");
}
@Test
public void loadsSqlTypes() throws Exception {
this.contextClassLoader.loadClass("java.sql.SQLException");
this.defaultScopeGroovyClassLoader.loadClass("java.sql.SQLException");
}
}