Skip to content

Commit 3adced9

Browse files
dreis2211wilkinsona
authored andcommitted
Remove workaround for JDK-8023130 in RunProcess
With JDK 8 being the baseline and JDK 7 not being supported anymore we can get rid of the workaround for a JDK 7 bug in ProcessBuilder.inheritIO on Windows machines. Closes spring-projectsgh-12337
1 parent 9882d87 commit 3adced9

File tree

1 file changed

+1
-68
lines changed
  • spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools

1 file changed

+1
-68
lines changed

Diff for: spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/RunProcess.java

+1-68
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,10 @@
1616

1717
package org.springframework.boot.loader.tools;
1818

19-
import java.io.BufferedReader;
2019
import java.io.File;
2120
import java.io.IOException;
22-
import java.io.InputStreamReader;
23-
import java.lang.reflect.Method;
2421
import java.util.Arrays;
2522
import java.util.Collection;
26-
import java.util.Locale;
27-
28-
import org.springframework.util.ReflectionUtils;
2923

3024
/**
3125
* Utility used to run a process.
@@ -38,9 +32,6 @@
3832
*/
3933
public class RunProcess {
4034

41-
private static final Method INHERIT_IO_METHOD = ReflectionUtils
42-
.findMethod(ProcessBuilder.class, "inheritIO");
43-
4435
private static final long JUST_ENDED_LIMIT = 500;
4536

4637
private File workingDirectory;
@@ -81,13 +72,10 @@ protected int run(boolean waitForProcess, Collection<String> args)
8172
builder.directory(this.workingDirectory);
8273
builder.command().addAll(args);
8374
builder.redirectErrorStream(true);
84-
boolean inheritedIO = inheritIO(builder);
75+
builder.inheritIO();
8576
try {
8677
Process process = builder.start();
8778
this.process = process;
88-
if (!inheritedIO) {
89-
redirectOutput(process);
90-
}
9179
SignalUtils.attachSignalHandler(this::handleSigInt);
9280
if (waitForProcess) {
9381
try {
@@ -108,61 +96,6 @@ protected int run(boolean waitForProcess, Collection<String> args)
10896
}
10997
}
11098

111-
private boolean inheritIO(ProcessBuilder builder) {
112-
if (isInheritIOBroken()) {
113-
return false;
114-
}
115-
try {
116-
INHERIT_IO_METHOD.invoke(builder);
117-
return true;
118-
}
119-
catch (Exception ex) {
120-
return false;
121-
}
122-
}
123-
124-
// There's a bug in the Windows VM (https://bugs.openjdk.java.net/browse/JDK-8023130)
125-
// that means we need to avoid inheritIO
126-
private static boolean isInheritIOBroken() {
127-
if (!System.getProperty("os.name", "none").toLowerCase(Locale.ENGLISH)
128-
.contains("windows")) {
129-
return false;
130-
}
131-
String runtime = System.getProperty("java.runtime.version");
132-
if (!runtime.startsWith("1.7")) {
133-
return false;
134-
}
135-
String[] tokens = runtime.split("_");
136-
if (tokens.length < 2) {
137-
return true; // No idea actually, shouldn't happen
138-
}
139-
try {
140-
Integer build = Integer.valueOf(tokens[1].split("[^0-9]")[0]);
141-
if (build < 60) {
142-
return true;
143-
}
144-
}
145-
catch (Exception ex) {
146-
return true;
147-
}
148-
return false;
149-
}
150-
151-
private void redirectOutput(Process process) {
152-
new Thread(() -> {
153-
try (BufferedReader reader = new BufferedReader(
154-
new InputStreamReader(process.getInputStream()))) {
155-
reader.lines().forEach((line) -> {
156-
System.out.println(line);
157-
System.out.flush();
158-
});
159-
}
160-
catch (Exception ex) {
161-
// Ignore
162-
}
163-
}).start();
164-
}
165-
16699
/**
167100
* Return the running process.
168101
* @return the process or {@code null}

0 commit comments

Comments
 (0)