Use Class.forName rather than ClassLoader.loadClass

This commit changes uses of ClassLoader.loadClass to Class.forName for
consistency with what was initiated in #19342 and better compatibility
with GraalVM.

Closes gh-19824
This commit is contained in:
Stephane Nicoll
2020-01-23 10:47:53 +01:00
parent 797c30f952
commit 95be419527
13 changed files with 37 additions and 37 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2020 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.
@@ -59,7 +59,7 @@ public class SpringApplicationLauncher {
public Object launch(Class<?>[] sources, String[] args) throws Exception {
Map<String, Object> defaultProperties = new HashMap<>();
defaultProperties.put("spring.groovy.template.check-template-location", "false");
Class<?> applicationClass = this.classLoader.loadClass(getSpringApplicationClassName());
Class<?> applicationClass = Class.forName(getSpringApplicationClassName(), false, this.classLoader);
Constructor<?> constructor = applicationClass.getDeclaredConstructor(Class[].class);
constructor.setAccessible(true);
Object application = constructor.newInstance((Object) sources);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2020 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.
@@ -72,7 +72,7 @@ public class SpringApplicationWebApplicationInitializer extends SpringBootServle
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
Class<?>[] sourceClasses = new Class<?>[this.sources.length];
for (int i = 0; i < this.sources.length; i++) {
sourceClasses[i] = classLoader.loadClass(this.sources[i]);
sourceClasses[i] = Class.forName(this.sources[i], false, classLoader);
}
return builder.sources(sourceClasses).properties("spring.groovy.template.check-template-location=false");
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2020 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.
@@ -73,7 +73,7 @@ public final class PackagedSpringApplicationLauncher {
private Class<?>[] loadClasses(ClassLoader classLoader, String[] names) throws ClassNotFoundException {
Class<?>[] classes = new Class<?>[names.length];
for (int i = 0; i < names.length; i++) {
classes[i] = classLoader.loadClass(names[i]);
classes[i] = Class.forName(names[i], false, classLoader);
}
return classes;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2020 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.
@@ -238,7 +238,7 @@ public class ExtendedGroovyClassLoader extends GroovyClassLoader {
@Override
protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {
if (!name.startsWith("java.")) {
this.groovyOnlyClassLoader.loadClass(name);
Class.forName(name, false, this.groovyOnlyClassLoader);
}
return super.loadClass(name, resolve);
}