diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/session/SessionAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/session/SessionAutoConfiguration.java index ea9e253b42..357e6badd8 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/session/SessionAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/session/SessionAutoConfiguration.java @@ -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> candidates, String type) { try { - Class candidate = this.classLoader.loadClass(type); + Class candidate = Class.forName(type, false, this.classLoader); if (candidate != null) { candidates.add(candidate); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionalOnJavaTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionalOnJavaTests.java index d445c720fd..f9ef8ab066 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionalOnJavaTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionalOnJavaTests.java @@ -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(); diff --git a/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/app/SpringApplicationLauncher.java b/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/app/SpringApplicationLauncher.java index 08a9d3ee1b..ade6ad81f6 100644 --- a/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/app/SpringApplicationLauncher.java +++ b/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/app/SpringApplicationLauncher.java @@ -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 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); diff --git a/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/app/SpringApplicationWebApplicationInitializer.java b/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/app/SpringApplicationWebApplicationInitializer.java index 5911d47c26..94cea0dc0e 100644 --- a/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/app/SpringApplicationWebApplicationInitializer.java +++ b/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/app/SpringApplicationWebApplicationInitializer.java @@ -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"); } diff --git a/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/archive/PackagedSpringApplicationLauncher.java b/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/archive/PackagedSpringApplicationLauncher.java index d0f07c7bb9..3392498cdf 100644 --- a/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/archive/PackagedSpringApplicationLauncher.java +++ b/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/archive/PackagedSpringApplicationLauncher.java @@ -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; } diff --git a/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/ExtendedGroovyClassLoader.java b/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/ExtendedGroovyClassLoader.java index 98e08b4a42..2a5ac31b59 100644 --- a/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/ExtendedGroovyClassLoader.java +++ b/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/ExtendedGroovyClassLoader.java @@ -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); } diff --git a/spring-boot-project/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/ExtendedGroovyClassLoaderTests.java b/spring-boot-project/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/ExtendedGroovyClassLoaderTests.java index 0ff98234a0..d61bc90e69 100644 --- a/spring-boot-project/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/ExtendedGroovyClassLoaderTests.java +++ b/spring-boot-project/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/ExtendedGroovyClassLoaderTests.java @@ -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. @@ -35,27 +35,27 @@ class ExtendedGroovyClassLoaderTests { @Test void loadsGroovyFromSameClassLoader() throws Exception { - Class c1 = this.contextClassLoader.loadClass("groovy.lang.Script"); - Class c2 = this.defaultScopeGroovyClassLoader.loadClass("groovy.lang.Script"); + Class c1 = Class.forName("groovy.lang.Script", false, this.contextClassLoader); + Class c2 = Class.forName("groovy.lang.Script", false, this.defaultScopeGroovyClassLoader); assertThat(c1.getClassLoader()).isSameAs(c2.getClassLoader()); } @Test void filtersNonGroovy() throws Exception { - this.contextClassLoader.loadClass("org.springframework.util.StringUtils"); - assertThatExceptionOfType(ClassNotFoundException.class) - .isThrownBy(() -> this.defaultScopeGroovyClassLoader.loadClass("org.springframework.util.StringUtils")); + Class.forName("org.springframework.util.StringUtils", false, this.contextClassLoader); + assertThatExceptionOfType(ClassNotFoundException.class).isThrownBy( + () -> Class.forName("org.springframework.util.StringUtils", false, this.defaultScopeGroovyClassLoader)); } @Test void loadsJavaTypes() throws Exception { - this.defaultScopeGroovyClassLoader.loadClass("java.lang.Boolean"); + Class.forName("java.lang.Boolean", false, this.defaultScopeGroovyClassLoader); } @Test void loadsSqlTypes() throws Exception { - this.contextClassLoader.loadClass("java.sql.SQLException"); - this.defaultScopeGroovyClassLoader.loadClass("java.sql.SQLException"); + Class.forName("java.sql.SQLException", false, this.contextClassLoader); + Class.forName("java.sql.SQLException", false, this.defaultScopeGroovyClassLoader); } } diff --git a/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/restart/classloader/RestartClassLoaderTests.java b/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/restart/classloader/RestartClassLoaderTests.java index 509eececfc..0613600270 100644 --- a/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/restart/classloader/RestartClassLoaderTests.java +++ b/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/restart/classloader/RestartClassLoaderTests.java @@ -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. @@ -125,13 +125,13 @@ class RestartClassLoaderTests { @Test void loadClassFromReloadableUrl() throws Exception { - Class loaded = this.reloadClassLoader.loadClass(PACKAGE + ".Sample"); + Class loaded = Class.forName(PACKAGE + ".Sample", false, this.reloadClassLoader); assertThat(loaded.getClassLoader()).isEqualTo(this.reloadClassLoader); } @Test void loadClassFromParent() throws Exception { - Class loaded = this.reloadClassLoader.loadClass(PACKAGE + ".SampleParent"); + Class loaded = Class.forName(PACKAGE + ".SampleParent", false, this.reloadClassLoader); assertThat(loaded.getClassLoader()).isEqualTo(getClass().getClassLoader()); } @@ -180,7 +180,7 @@ class RestartClassLoaderTests { String name = PACKAGE_PATH + "/Sample.class"; this.updatedFiles.addFile(name, new ClassLoaderFile(Kind.DELETED, null)); assertThatExceptionOfType(ClassNotFoundException.class) - .isThrownBy(() -> this.reloadClassLoader.loadClass(PACKAGE + ".Sample")); + .isThrownBy(() -> Class.forName(PACKAGE + ".Sample", false, this.reloadClassLoader)); } @Test @@ -188,7 +188,7 @@ class RestartClassLoaderTests { String name = PACKAGE_PATH + "/Sample.class"; this.updatedFiles.addFile(name, new ClassLoaderFile(Kind.MODIFIED, new byte[10])); assertThatExceptionOfType(ClassFormatError.class) - .isThrownBy(() -> this.reloadClassLoader.loadClass(PACKAGE + ".Sample")); + .isThrownBy(() -> Class.forName(PACKAGE + ".Sample", false, this.reloadClassLoader)); } @Test @@ -196,7 +196,7 @@ class RestartClassLoaderTests { String name = PACKAGE_PATH + "/SampleParent.class"; byte[] bytes = FileCopyUtils.copyToByteArray(getClass().getResourceAsStream("SampleParent.class")); this.updatedFiles.addFile(name, new ClassLoaderFile(Kind.ADDED, bytes)); - Class loaded = this.reloadClassLoader.loadClass(PACKAGE + ".SampleParent"); + Class loaded = Class.forName(PACKAGE + ".SampleParent", false, this.reloadClassLoader); assertThat(loaded.getClassLoader()).isEqualTo(this.reloadClassLoader); } diff --git a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/context/FilteredClassLoaderTests.java b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/context/FilteredClassLoaderTests.java index bfbb355dbf..e184652899 100644 --- a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/context/FilteredClassLoaderTests.java +++ b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/context/FilteredClassLoaderTests.java @@ -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. @@ -43,7 +43,7 @@ class FilteredClassLoaderTests { try (FilteredClassLoader classLoader = new FilteredClassLoader( FilteredClassLoaderTests.class.getPackage().getName())) { assertThatExceptionOfType(ClassNotFoundException.class) - .isThrownBy(() -> classLoader.loadClass(getClass().getName())); + .isThrownBy(() -> Class.forName(getClass().getName(), false, classLoader)); } } @@ -51,14 +51,14 @@ class FilteredClassLoaderTests { void loadClassWhenFilteredOnClassShouldThrowClassNotFound() throws Exception { try (FilteredClassLoader classLoader = new FilteredClassLoader(FilteredClassLoaderTests.class)) { assertThatExceptionOfType(ClassNotFoundException.class) - .isThrownBy(() -> classLoader.loadClass(getClass().getName())); + .isThrownBy(() -> Class.forName(getClass().getName(), false, classLoader)); } } @Test void loadClassWhenNotFilteredShouldLoadClass() throws Exception { FilteredClassLoader classLoader = new FilteredClassLoader((className) -> false); - Class loaded = classLoader.loadClass(getClass().getName()); + Class loaded = Class.forName(getClass().getName(), false, classLoader); assertThat(loaded.getName()).isEqualTo(getClass().getName()); classLoader.close(); } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/fieldvalues/javac/ReflectionWrapper.java b/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/fieldvalues/javac/ReflectionWrapper.java index 92e3edeb53..152750385c 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/fieldvalues/javac/ReflectionWrapper.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/fieldvalues/javac/ReflectionWrapper.java @@ -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); diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/run-exclude/src/main/java/org/test/SampleApplication.java b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/run-exclude/src/main/java/org/test/SampleApplication.java index 3b5c9175fb..56892c15b9 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/run-exclude/src/main/java/org/test/SampleApplication.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/run-exclude/src/main/java/org/test/SampleApplication.java @@ -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) { diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/AbstractRunMojo.java b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/AbstractRunMojo.java index 9091fc4a3b..e3f0da820c 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/AbstractRunMojo.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/AbstractRunMojo.java @@ -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); diff --git a/spring-boot-project/spring-boot-tools/spring-boot-test-support/src/main/java/org/springframework/boot/testsupport/classpath/ModifiedClassPathExtension.java b/spring-boot-project/spring-boot-tools/spring-boot-test-support/src/main/java/org/springframework/boot/testsupport/classpath/ModifiedClassPathExtension.java index 38e5f17faf..38118df176 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-test-support/src/main/java/org/springframework/boot/testsupport/classpath/ModifiedClassPathExtension.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-test-support/src/main/java/org/springframework/boot/testsupport/classpath/ModifiedClassPathExtension.java @@ -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();