Skip to content

Commit aa7125f

Browse files
Fix NullPointerException when java home not provided (#5151)
Fixes #5149 Someone I can't get a reliably repro of that failure, but this PR should theoretically fix the mechanism through which the failure happens by making the launcher-daemon protocol robust against null strings --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent 542fcd2 commit aa7125f

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

runner/client/src/mill/client/ClientUtil.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public static Map<String, String> parseMap(InputStream argStream) throws IOExcep
6565
public static String readString(InputStream inputStream) throws IOException {
6666
// Result is between 0 and 255, hence the loop.
6767
final int length = readInt(inputStream);
68+
if (length == -1) return null;
6869
final byte[] arr = new byte[length];
6970
int total = 0;
7071
while (total < length) {
@@ -78,9 +79,13 @@ public static String readString(InputStream inputStream) throws IOException {
7879
}
7980

8081
public static void writeString(OutputStream outputStream, String string) throws IOException {
81-
final byte[] bytes = string.getBytes(utf8);
82-
writeInt(outputStream, bytes.length);
83-
outputStream.write(bytes);
82+
if (string == null) {
83+
writeInt(outputStream, -1);
84+
} else {
85+
final byte[] bytes = string.getBytes(utf8);
86+
writeInt(outputStream, bytes.length);
87+
outputStream.write(bytes);
88+
}
8489
}
8590

8691
public static void writeInt(OutputStream out, int i) throws IOException {

runner/client/test/src/mill/client/ClientTests.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,12 @@ public void readWriteInt() throws Exception {
4848
@Test
4949
public void readWriteString() throws Exception {
5050
String[] examples = {
51-
"", "hello", "i am cow", "i am cow\nhear me moo\ni weight twice as much as you", "我是一个叉烧包",
51+
"",
52+
"hello",
53+
"i am cow",
54+
"i am cow\nhear me moo\ni weight twice as much as you",
55+
"我是一个叉烧包",
56+
null
5257
};
5358
for (String example : examples) {
5459
checkStringRoundTrip(example);

0 commit comments

Comments
 (0)