Skip to content

Commit 46155ca

Browse files
committed
Tolerate illegal reflective access warnings when testing with Java 9
See gh-7226
1 parent ebf3b47 commit 46155ca

File tree

1 file changed

+40
-10
lines changed

1 file changed

+40
-10
lines changed

spring-boot-cli/src/it/java/org/springframework/boot/cli/JarCommandIT.java

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,22 @@
4040
*/
4141
public class JarCommandIT {
4242

43+
private static final boolean java9OrLater;
44+
45+
static {
46+
boolean loaded = false;
47+
try {
48+
Class.forName("java.security.cert.URICertStoreParameters");
49+
loaded = true;
50+
}
51+
catch (Exception ex) {
52+
// Continue
53+
}
54+
finally {
55+
java9OrLater = loaded;
56+
}
57+
}
58+
4359
private final CommandLineInvoker cli = new CommandLineInvoker(
4460
new File("src/it/resources/jar-command"));
4561

@@ -67,19 +83,25 @@ public void jarCreationWithGrabResolver() throws Exception {
6783
Invocation invocation = this.cli.invoke("run", jar.getAbsolutePath(),
6884
"bad.groovy");
6985
invocation.await();
70-
assertThat(invocation.getErrorOutput(), equalTo(""));
86+
if (!java9OrLater) {
87+
assertThat(invocation.getErrorOutput(), equalTo(""));
88+
}
7189
invocation = this.cli.invoke("jar", jar.getAbsolutePath(), "bad.groovy");
7290
invocation.await();
73-
assertEquals(invocation.getErrorOutput(), 0,
74-
invocation.getErrorOutput().length());
91+
if (!java9OrLater) {
92+
assertEquals(invocation.getErrorOutput(), 0,
93+
invocation.getErrorOutput().length());
94+
}
7595
assertTrue(jar.exists());
7696

7797
Process process = new JavaExecutable()
7898
.processBuilder("-jar", jar.getAbsolutePath()).start();
7999
invocation = new Invocation(process);
80100
invocation.await();
81101

82-
assertThat(invocation.getErrorOutput(), equalTo(""));
102+
if (!java9OrLater) {
103+
assertThat(invocation.getErrorOutput(), equalTo(""));
104+
}
83105
}
84106

85107
@Test
@@ -88,16 +110,20 @@ public void jarCreation() throws Exception {
88110
Invocation invocation = this.cli.invoke("jar", jar.getAbsolutePath(),
89111
"jar.groovy");
90112
invocation.await();
91-
assertEquals(invocation.getErrorOutput(), 0,
92-
invocation.getErrorOutput().length());
113+
if (!java9OrLater) {
114+
assertEquals(invocation.getErrorOutput(), 0,
115+
invocation.getErrorOutput().length());
116+
}
93117
assertTrue(jar.exists());
94118

95119
Process process = new JavaExecutable()
96120
.processBuilder("-jar", jar.getAbsolutePath()).start();
97121
invocation = new Invocation(process);
98122
invocation.await();
99123

100-
assertThat(invocation.getErrorOutput(), equalTo(""));
124+
if (!java9OrLater) {
125+
assertThat(invocation.getErrorOutput(), equalTo(""));
126+
}
101127
assertThat(invocation.getStandardOutput(), containsString("Hello World!"));
102128
assertThat(invocation.getStandardOutput(),
103129
containsString("/BOOT-INF/classes!/public/public.txt"));
@@ -118,16 +144,20 @@ public void jarCreationWithIncludes() throws Exception {
118144
Invocation invocation = this.cli.invoke("jar", jar.getAbsolutePath(), "--include",
119145
"-public/**,-resources/**", "jar.groovy");
120146
invocation.await();
121-
assertEquals(invocation.getErrorOutput(), 0,
122-
invocation.getErrorOutput().length());
147+
if (!java9OrLater) {
148+
assertEquals(invocation.getErrorOutput(), 0,
149+
invocation.getErrorOutput().length());
150+
}
123151
assertTrue(jar.exists());
124152

125153
Process process = new JavaExecutable()
126154
.processBuilder("-jar", jar.getAbsolutePath()).start();
127155
invocation = new Invocation(process);
128156
invocation.await();
129157

130-
assertThat(invocation.getErrorOutput(), equalTo(""));
158+
if (!java9OrLater) {
159+
assertThat(invocation.getErrorOutput(), equalTo(""));
160+
}
131161
assertThat(invocation.getStandardOutput(), containsString("Hello World!"));
132162
assertThat(invocation.getStandardOutput(),
133163
not(containsString("/public/public.txt")));

0 commit comments

Comments
 (0)