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.
|
||||
@@ -54,7 +54,7 @@ class ReflectionWrapper {
|
||||
|
||||
protected static Class<?> findClass(ClassLoader classLoader, String name) {
|
||||
try {
|
||||
return classLoader.loadClass(name);
|
||||
return Class.forName(name, false, classLoader);
|
||||
}
|
||||
catch (ClassNotFoundException ex) {
|
||||
throw new IllegalStateException(ex);
|
||||
|
||||
@@ -32,7 +32,7 @@ public class SampleApplication {
|
||||
|
||||
try {
|
||||
ClassLoader classLoader = SampleApplication.class.getClassLoader();
|
||||
classLoader.loadClass(className);
|
||||
Class.forName(className, false, classLoader);
|
||||
return true;
|
||||
}
|
||||
catch (ClassNotFoundException e) {
|
||||
|
||||
@@ -559,7 +559,7 @@ public abstract class AbstractRunMojo extends AbstractDependencyFilterMojo {
|
||||
Thread thread = Thread.currentThread();
|
||||
ClassLoader classLoader = thread.getContextClassLoader();
|
||||
try {
|
||||
Class<?> startClass = classLoader.loadClass(this.startClassName);
|
||||
Class<?> startClass = Class.forName(this.startClassName, false, classLoader);
|
||||
Method mainMethod = startClass.getMethod("main", String[].class);
|
||||
if (!mainMethod.isAccessible()) {
|
||||
mainMethod.setAccessible(true);
|
||||
|
||||
@@ -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.
|
||||
@@ -96,7 +96,7 @@ class ModifiedClassPathExtension implements InvocationInterceptor {
|
||||
}
|
||||
|
||||
private void runTest(ClassLoader classLoader, String testClassName, String testMethodName) throws Throwable {
|
||||
Class<?> testClass = classLoader.loadClass(testClassName);
|
||||
Class<?> testClass = Class.forName(testClassName, false, classLoader);
|
||||
Method testMethod = findMethod(testClass, testMethodName);
|
||||
LauncherDiscoveryRequest request = new LauncherDiscoveryRequestBuilder(classLoader)
|
||||
.selectors(DiscoverySelectors.selectMethod(testClass, testMethod)).build();
|
||||
|
||||
Reference in New Issue
Block a user