mirror of
https://github.com/spring-projects/spring-boot.git
synced 2026-09-17 12:09:16 +00:00
Ensure that only spring-core's ReflectionUtils is used
Closes gh-44837
This commit is contained in:
+1
-1
@@ -25,7 +25,6 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
import io.lettuce.core.dynamic.support.ReflectionUtils;
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.params.ParameterizedTest;
|
import org.junit.jupiter.params.ParameterizedTest;
|
||||||
import org.junit.jupiter.params.provider.MethodSource;
|
import org.junit.jupiter.params.provider.MethodSource;
|
||||||
@@ -48,6 +47,7 @@ import org.springframework.integration.context.IntegrationProperties;
|
|||||||
import org.springframework.mock.env.MockEnvironment;
|
import org.springframework.mock.env.MockEnvironment;
|
||||||
import org.springframework.test.util.ReflectionTestUtils;
|
import org.springframework.test.util.ReflectionTestUtils;
|
||||||
import org.springframework.util.ClassUtils;
|
import org.springframework.util.ClassUtils;
|
||||||
|
import org.springframework.util.ReflectionUtils;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||||
|
|||||||
+15
-6
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2012-2024 the original author or authors.
|
* Copyright 2012-2025 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.
|
||||||
@@ -18,6 +18,7 @@ package org.springframework.boot.context.embedded;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.lang.reflect.Constructor;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
@@ -41,12 +42,13 @@ import org.junit.jupiter.api.extension.ParameterContext;
|
|||||||
import org.junit.jupiter.api.extension.ParameterResolver;
|
import org.junit.jupiter.api.extension.ParameterResolver;
|
||||||
import org.junit.jupiter.api.extension.TestTemplateInvocationContext;
|
import org.junit.jupiter.api.extension.TestTemplateInvocationContext;
|
||||||
import org.junit.jupiter.api.extension.TestTemplateInvocationContextProvider;
|
import org.junit.jupiter.api.extension.TestTemplateInvocationContextProvider;
|
||||||
import org.junit.platform.commons.util.ReflectionUtils;
|
|
||||||
|
|
||||||
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.boot.testsupport.BuildOutput;
|
import org.springframework.boot.testsupport.BuildOutput;
|
||||||
import org.springframework.http.client.ClientHttpResponse;
|
import org.springframework.http.client.ClientHttpResponse;
|
||||||
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
|
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
|
||||||
import org.springframework.util.FileSystemUtils;
|
import org.springframework.util.FileSystemUtils;
|
||||||
|
import org.springframework.util.ReflectionUtils;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
import org.springframework.web.client.ResponseErrorHandler;
|
import org.springframework.web.client.ResponseErrorHandler;
|
||||||
import org.springframework.web.client.RestTemplate;
|
import org.springframework.web.client.RestTemplate;
|
||||||
@@ -119,10 +121,17 @@ class EmbeddedServerContainerInvocationContextProvider
|
|||||||
if (this.launcherCache.containsKey(cacheKey)) {
|
if (this.launcherCache.containsKey(cacheKey)) {
|
||||||
return this.launcherCache.get(cacheKey);
|
return this.launcherCache.get(cacheKey);
|
||||||
}
|
}
|
||||||
AbstractApplicationLauncher launcher = ReflectionUtils.newInstance(launcherClass, application,
|
try {
|
||||||
new File(buildOutput.getRootLocation(), "app-launcher-" + UUID.randomUUID()));
|
Constructor<? extends AbstractApplicationLauncher> constructor = ReflectionUtils
|
||||||
this.launcherCache.put(cacheKey, launcher);
|
.accessibleConstructor(launcherClass, Application.class, File.class);
|
||||||
return launcher;
|
AbstractApplicationLauncher launcher = BeanUtils.instantiateClass(constructor, application,
|
||||||
|
new File(buildOutput.getRootLocation(), "app-launcher-" + UUID.randomUUID()));
|
||||||
|
this.launcherCache.put(cacheKey, launcher);
|
||||||
|
return launcher;
|
||||||
|
}
|
||||||
|
catch (NoSuchMethodException ex) {
|
||||||
|
throw new IllegalStateException("Launcher class %s does not have an (Application, File) constructor");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Application getApplication(EmbeddedServletContainerTest annotation, String container) {
|
private Application getApplication(EmbeddedServletContainerTest annotation, String container) {
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
<property name="illegalPkgs"
|
<property name="illegalPkgs"
|
||||||
value="^sun.*, ^org\.apache\.commons\.(?!compress|dbcp2|logging|pool2).*, ^com\.datastax\.oss\.driver\.shaded.*, ^com\.google\.common.*, ^io\.micrometer\.core\.lang.*, ^io\.micrometer\.shaded.*, ^org\.jetbrains\.annotations.*, ^org\.testcontainers\.shaded.*" />
|
value="^sun.*, ^org\.apache\.commons\.(?!compress|dbcp2|logging|pool2).*, ^com\.datastax\.oss\.driver\.shaded.*, ^com\.google\.common.*, ^io\.micrometer\.core\.lang.*, ^io\.micrometer\.shaded.*, ^org\.jetbrains\.annotations.*, ^org\.testcontainers\.shaded.*" />
|
||||||
<property name="illegalClasses"
|
<property name="illegalClasses"
|
||||||
value="^com\.hazelcast\.util\.Base64, ^org\.junit\.rules\.ExpectedException, ^org\.mockito\.InjectMocks, ^org\.slf4j\.LoggerFactory, ^org.springframework.context.annotation.ScannedGenericBeanDefinition, ^reactor\.core\.support\.Assert"/>
|
value="^com\.hazelcast\.util\.Base64, ^org\.junit\.rules\.ExpectedException, ^org\.mockito\.InjectMocks, ^org\.slf4j\.LoggerFactory, ^org.springframework.context.annotation.ScannedGenericBeanDefinition, ^reactor\.core\.support\.Assert, ^(?!org\.springframework\.util\.).*ReflectionUtils"/>
|
||||||
</module>
|
</module>
|
||||||
<module
|
<module
|
||||||
name="com.puppycrawl.tools.checkstyle.checks.imports.IllegalImportCheck">
|
name="com.puppycrawl.tools.checkstyle.checks.imports.IllegalImportCheck">
|
||||||
|
|||||||
Reference in New Issue
Block a user