Skip to content

Commit 4098735

Browse files
committed
Attempt reading after success exit.
1 parent 5d42918 commit 4098735

File tree

1 file changed

+31
-35
lines changed

1 file changed

+31
-35
lines changed

byte-buddy-agent/src/main/java/net/bytebuddy/agent/VirtualMachine.java

Lines changed: 31 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2404,20 +2404,18 @@ public int getOwnerIdOf(File file) {
24042404
"%u",
24052405
file.getAbsolutePath()});
24062406
int attempts = this.attempts;
2407-
boolean exited = false;
2408-
String line;
2409-
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream(), "UTF-8"));
2410-
try {
2411-
line = reader.readLine();
2412-
} finally {
2413-
//reader.close();
2414-
}
2407+
String line = null;
24152408
do {
24162409
try {
24172410
if (process.exitValue() != 0) {
24182411
throw new IllegalStateException("Error while executing stat");
24192412
}
2420-
exited = true;
2413+
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream(), "UTF-8"));
2414+
try {
2415+
line = reader.readLine();
2416+
} finally {
2417+
reader.close();
2418+
}
24212419
break;
24222420
} catch (IllegalThreadStateException ignored) {
24232421
try {
@@ -2428,7 +2426,7 @@ public int getOwnerIdOf(File file) {
24282426
}
24292427
}
24302428
} while (--attempts > 0);
2431-
if (!exited) {
2429+
if (line == null) {
24322430
process.destroy();
24332431
throw new IllegalStateException("Command for stat did not exit in time");
24342432
}
@@ -2484,23 +2482,23 @@ public int getOwnerIdOf(File file) {
24842482
try {
24852483
Process process = Runtime.getRuntime().exec(new String[]{"istat", file.getAbsolutePath()});
24862484
int attempts = this.attempts;
2487-
boolean exited = false;
2488-
StringBuilder output = new StringBuilder();
2489-
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream(), "UTF-8"));
2490-
try {
2491-
String line;
2492-
while ((line = reader.readLine()) != null) {
2493-
output.append(line).append("\n");
2494-
}
2495-
} finally {
2496-
//reader.close();
2497-
}
2485+
String lines = null;
24982486
do {
24992487
try {
25002488
if (process.exitValue() != 0) {
25012489
throw new IllegalStateException("Error while executing istat");
25022490
}
2503-
exited = true;
2491+
StringBuilder output = new StringBuilder();
2492+
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream(), "UTF-8"));
2493+
try {
2494+
String line;
2495+
while ((line = reader.readLine()) != null) {
2496+
output.append(line).append("\n");
2497+
}
2498+
} finally {
2499+
reader.close();
2500+
}
2501+
lines = output.toString();
25042502
break;
25052503
} catch (IllegalThreadStateException ignored) {
25062504
try {
@@ -2511,15 +2509,15 @@ public int getOwnerIdOf(File file) {
25112509
}
25122510
}
25132511
} while (--attempts > 0);
2514-
if (!exited) {
2512+
if (lines == null) {
25152513
process.destroy();
25162514
throw new IllegalStateException("Command for istat did not exit in time");
25172515
}
2518-
Matcher matcher = AIX_OWNER_PATTERN.matcher(output.toString());
2516+
Matcher matcher = AIX_OWNER_PATTERN.matcher(lines);
25192517
if (matcher.find()) {
25202518
return Integer.parseInt(matcher.group(1));
25212519
} else {
2522-
throw new IllegalStateException("Unable to parse response from istat command: " + output);
2520+
throw new IllegalStateException("Unable to parse response from istat command: " + lines);
25232521
}
25242522
} catch (IOException exception) {
25252523
throw new IllegalStateException("Unable to execute istat command", exception);
@@ -2572,20 +2570,18 @@ public int getOwnerIdOf(File file) {
25722570
"%u",
25732571
file.getAbsolutePath()});
25742572
int attempts = this.attempts;
2575-
boolean exited = false;
2576-
String line;
2577-
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream(), "UTF-8"));
2578-
try {
2579-
line = reader.readLine();
2580-
} finally {
2581-
//reader.close();
2582-
}
2573+
String line = null;
25832574
do {
25842575
try {
25852576
if (process.exitValue() != 0) {
25862577
throw new IllegalStateException("Error while executing stat");
25872578
}
2588-
exited = true;
2579+
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream(), "UTF-8"));
2580+
try {
2581+
line = reader.readLine();
2582+
} finally {
2583+
reader.close();
2584+
}
25892585
break;
25902586
} catch (IllegalThreadStateException ignored) {
25912587
try {
@@ -2596,7 +2592,7 @@ public int getOwnerIdOf(File file) {
25962592
}
25972593
}
25982594
} while (--attempts > 0);
2599-
if (!exited) {
2595+
if (line == null) {
26002596
process.destroy();
26012597
throw new IllegalStateException("Command for stat did not exit in time");
26022598
}

0 commit comments

Comments
 (0)