Commit e044817f authored by Stephane Nicoll's avatar Stephane Nicoll

Migrate remaining use of ClassLoader.loadClass to Class.forName

Closes gh-19824
parent 820c671d
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -93,7 +93,7 @@ public class DependencyCustomizer { ...@@ -93,7 +93,7 @@ public class DependencyCustomizer {
protected boolean canAdd() { protected boolean canAdd() {
for (String className : classNames) { for (String className : classNames) {
try { try {
DependencyCustomizer.this.loader.loadClass(className); Class.forName(className, false, DependencyCustomizer.this.loader);
} }
catch (Exception ex) { catch (Exception ex) {
return true; return true;
...@@ -116,7 +116,7 @@ public class DependencyCustomizer { ...@@ -116,7 +116,7 @@ public class DependencyCustomizer {
protected boolean canAdd() { protected boolean canAdd() {
for (String className : classNames) { for (String className : classNames) {
try { try {
DependencyCustomizer.this.loader.loadClass(className); Class.forName(className, false, DependencyCustomizer.this.loader);
return false; return false;
} }
catch (Exception ex) { catch (Exception ex) {
......
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -44,7 +44,7 @@ class RestartLauncher extends Thread { ...@@ -44,7 +44,7 @@ class RestartLauncher extends Thread {
@Override @Override
public void run() { public void run() {
try { try {
Class<?> mainClass = getContextClassLoader().loadClass(this.mainClassName); Class<?> mainClass = Class.forName(this.mainClassName, false, getContextClassLoader());
Method mainMethod = mainClass.getDeclaredMethod("main", String[].class); Method mainMethod = mainClass.getDeclaredMethod("main", String[].class);
mainMethod.invoke(null, new Object[] { this.args }); mainMethod.invoke(null, new Object[] { this.args });
} }
......
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -141,7 +141,7 @@ public class RestartClassLoader extends URLClassLoader implements SmartClassLoad ...@@ -141,7 +141,7 @@ public class RestartClassLoader extends URLClassLoader implements SmartClassLoad
loadedClass = findClass(name); loadedClass = findClass(name);
} }
catch (ClassNotFoundException ex) { catch (ClassNotFoundException ex) {
loadedClass = getParent().loadClass(name); loadedClass = Class.forName(name, false, getParent());
} }
} }
if (resolve) { if (resolve) {
......
...@@ -43,7 +43,7 @@ public class MainMethodRunner { ...@@ -43,7 +43,7 @@ public class MainMethodRunner {
} }
public void run() throws Exception { public void run() throws Exception {
Class<?> mainClass = Thread.currentThread().getContextClassLoader().loadClass(this.mainClassName); Class<?> mainClass = Class.forName(this.mainClassName, false, Thread.currentThread().getContextClassLoader());
Method mainMethod = mainClass.getDeclaredMethod("main", String[].class); Method mainMethod = mainClass.getDeclaredMethod("main", String[].class);
mainMethod.setAccessible(true); mainMethod.setAccessible(true);
mainMethod.invoke(null, new Object[] { this.args }); mainMethod.invoke(null, new Object[] { this.args });
......
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -76,7 +76,7 @@ final class ModifiedClassPathClassLoader extends URLClassLoader { ...@@ -76,7 +76,7 @@ final class ModifiedClassPathClassLoader extends URLClassLoader {
@Override @Override
public Class<?> loadClass(String name) throws ClassNotFoundException { public Class<?> loadClass(String name) throws ClassNotFoundException {
if (name.startsWith("org.junit") || name.startsWith("org.hamcrest")) { if (name.startsWith("org.junit") || name.startsWith("org.hamcrest")) {
return this.junitLoader.loadClass(name); return Class.forName(name, false, this.junitLoader);
} }
return super.loadClass(name); return super.loadClass(name);
} }
......
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -106,7 +106,8 @@ class NoSuchMethodFailureAnalyzer extends AbstractFailureAnalyzer<NoSuchMethodEr ...@@ -106,7 +106,8 @@ class NoSuchMethodFailureAnalyzer extends AbstractFailureAnalyzer<NoSuchMethodEr
private URL getActual(String className) { private URL getActual(String className) {
try { try {
return getClass().getClassLoader().loadClass(className).getProtectionDomain().getCodeSource().getLocation(); return Class.forName(className, false, getClass().getClassLoader()).getProtectionDomain().getCodeSource()
.getLocation();
} }
catch (Throwable ex) { catch (Throwable ex) {
return null; return null;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment