Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
7a25e4ed
Commit
7a25e4ed
authored
Jun 16, 2021
by
dreis2211
Committed by
Phillip Webb
Jun 24, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Avoid illegal reflective access in CLI tests
See gh-26930
parent
093e7f7e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
13 additions
and
20 deletions
+13
-20
build.gradle
spring-boot-project/spring-boot-cli/build.gradle
+1
-0
CliTester.java
...src/test/java/org/springframework/boot/cli/CliTester.java
+1
-19
CliTesterSpringApplication.java
.../springframework/boot/cli/CliTesterSpringApplication.java
+11
-1
No files found.
spring-boot-project/spring-boot-cli/build.gradle
View file @
7a25e4ed
...
@@ -56,6 +56,7 @@ dependencies {
...
@@ -56,6 +56,7 @@ dependencies {
loader
(
project
(
":spring-boot-project:spring-boot-tools:spring-boot-loader"
))
loader
(
project
(
":spring-boot-project:spring-boot-tools:spring-boot-loader"
))
testCompileOnly
(
"org.apache.tomcat.embed:tomcat-embed-core"
)
testImplementation
(
project
(
":spring-boot-project:spring-boot"
))
testImplementation
(
project
(
":spring-boot-project:spring-boot"
))
testImplementation
(
project
(
":spring-boot-project:spring-boot-tools:spring-boot-test-support"
))
testImplementation
(
project
(
":spring-boot-project:spring-boot-tools:spring-boot-test-support"
))
testImplementation
(
project
(
":spring-boot-project:spring-boot-test"
))
testImplementation
(
project
(
":spring-boot-project:spring-boot-test"
))
...
...
spring-boot-project/spring-boot-cli/src/test/java/org/springframework/boot/cli/CliTester.java
View file @
7a25e4ed
/*
/*
* Copyright 2012-202
0
the original author or authors.
* Copyright 2012-202
1
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.
...
@@ -22,9 +22,7 @@ import java.io.FileReader;
...
@@ -22,9 +22,7 @@ import java.io.FileReader;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.InputStream
;
import
java.io.InputStreamReader
;
import
java.io.InputStreamReader
;
import
java.lang.reflect.Field
;
import
java.net.URI
;
import
java.net.URI
;
import
java.net.URL
;
import
java.nio.file.Files
;
import
java.nio.file.Files
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.List
;
...
@@ -127,7 +125,6 @@ public class CliTester implements BeforeEachCallback, AfterEachCallback {
...
@@ -127,7 +125,6 @@ public class CliTester implements BeforeEachCallback, AfterEachCallback {
}
}
private
<
T
extends
OptionParsingCommand
>
Future
<
T
>
submitCommand
(
T
command
,
String
...
args
)
{
private
<
T
extends
OptionParsingCommand
>
Future
<
T
>
submitCommand
(
T
command
,
String
...
args
)
{
clearUrlHandler
();
final
String
[]
sources
=
getSources
(
args
);
final
String
[]
sources
=
getSources
(
args
);
return
Executors
.
newSingleThreadExecutor
().
submit
(()
->
{
return
Executors
.
newSingleThreadExecutor
().
submit
(()
->
{
ClassLoader
loader
=
Thread
.
currentThread
().
getContextClassLoader
();
ClassLoader
loader
=
Thread
.
currentThread
().
getContextClassLoader
();
...
@@ -152,21 +149,6 @@ public class CliTester implements BeforeEachCallback, AfterEachCallback {
...
@@ -152,21 +149,6 @@ public class CliTester implements BeforeEachCallback, AfterEachCallback {
});
});
}
}
/**
* The TomcatURLStreamHandlerFactory fails if the factory is already set, use
* reflection to reset it.
*/
private
void
clearUrlHandler
()
{
try
{
Field
field
=
URL
.
class
.
getDeclaredField
(
"factory"
);
field
.
setAccessible
(
true
);
field
.
set
(
null
,
null
);
}
catch
(
Exception
ex
)
{
throw
new
IllegalStateException
(
ex
);
}
}
protected
String
[]
getSources
(
String
...
args
)
{
protected
String
[]
getSources
(
String
...
args
)
{
final
String
[]
sources
=
new
String
[
args
.
length
];
final
String
[]
sources
=
new
String
[
args
.
length
];
for
(
int
i
=
0
;
i
<
args
.
length
;
i
++)
{
for
(
int
i
=
0
;
i
<
args
.
length
;
i
++)
{
...
...
spring-boot-project/spring-boot-cli/src/test/java/org/springframework/boot/cli/CliTesterSpringApplication.java
View file @
7a25e4ed
/*
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
21
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.
...
@@ -16,9 +16,12 @@
...
@@ -16,9 +16,12 @@
package
org
.
springframework
.
boot
.
cli
;
package
org
.
springframework
.
boot
.
cli
;
import
org.apache.catalina.webresources.TomcatURLStreamHandlerFactory
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.web.context.WebServerPortFileWriter
;
import
org.springframework.boot.web.context.WebServerPortFileWriter
;
import
org.springframework.context.ConfigurableApplicationContext
;
import
org.springframework.context.ConfigurableApplicationContext
;
import
org.springframework.util.ClassUtils
;
/**
/**
* Custom {@link SpringApplication} used by {@link CliTester}.
* Custom {@link SpringApplication} used by {@link CliTester}.
...
@@ -27,6 +30,13 @@ import org.springframework.context.ConfigurableApplicationContext;
...
@@ -27,6 +30,13 @@ import org.springframework.context.ConfigurableApplicationContext;
*/
*/
public
class
CliTesterSpringApplication
extends
SpringApplication
{
public
class
CliTesterSpringApplication
extends
SpringApplication
{
static
{
if
(
ClassUtils
.
isPresent
(
"org.apache.catalina.webresources.TomcatURLStreamHandlerFactory"
,
CliTesterSpringApplication
.
class
.
getClassLoader
()))
{
TomcatURLStreamHandlerFactory
.
disable
();
}
}
public
CliTesterSpringApplication
(
Class
<?>...
sources
)
{
public
CliTesterSpringApplication
(
Class
<?>...
sources
)
{
super
(
sources
);
super
(
sources
);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment