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

@@ -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) {

View File

@@ -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);