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:
@@ -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.
|
||||
@@ -242,7 +242,7 @@ public class SessionAutoConfiguration {
|
||||
|
||||
private void addCandidateIfAvailable(List<Class<?>> candidates, String type) {
|
||||
try {
|
||||
Class<?> candidate = this.classLoader.loadClass(type);
|
||||
Class<?> candidate = Class.forName(type, false, this.classLoader);
|
||||
if (candidate != null) {
|
||||
candidates.add(candidate);
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
@@ -104,7 +104,7 @@ class ConditionalOnJavaTests {
|
||||
|
||||
private String getJavaVersion(Class<?>... hiddenClasses) throws Exception {
|
||||
FilteredClassLoader classLoader = new FilteredClassLoader(hiddenClasses);
|
||||
Class<?> javaVersionClass = classLoader.loadClass(JavaVersion.class.getName());
|
||||
Class<?> javaVersionClass = Class.forName(JavaVersion.class.getName(), false, classLoader);
|
||||
Method getJavaVersionMethod = ReflectionUtils.findMethod(javaVersionClass, "getJavaVersion");
|
||||
Object javaVersion = ReflectionUtils.invokeMethod(getJavaVersionMethod, null);
|
||||
classLoader.close();
|
||||
|
||||
Reference in New Issue
Block a user