Skip to content

Commit b023d5c

Browse files
committed
8290083: ResponseBodyBeforeError: AssertionError or SSLException: Unsupported or unrecognized SSL message
Backport-of: 3b9059a1471ba74af8bf6a3c0e5b2e1140eb4afd
1 parent cb1a54a commit b023d5c

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

test/jdk/java/net/httpclient/ResponseBodyBeforeError.java

+23-7
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,10 @@ protected ServerSocket newServerSocket() throws IOException {
322322

323323
@Override
324324
public void run() {
325+
int maxUnexpected = 10; // if we get there too often we may
326+
// want to reassess the diagnosis
325327
while (!closed) {
328+
boolean accepted = false;
326329
try (Socket s = ss.accept()) {
327330
out.print(name + ": got connection ");
328331
InputStream is = s.getInputStream();
@@ -333,26 +336,39 @@ public void run() {
333336
readRequestHeaders(is);
334337

335338
String query = uriPath.getRawQuery();
336-
assert query != null;
339+
if (query == null) {
340+
throw new IOException("expected query not found in: " + uriPath);
341+
}
337342
String qv = query.split("=")[1];
338343
int len;
339344
if (qv.equals("all")) {
340345
len = responseBody().getBytes(US_ASCII).length;
341346
} else {
342-
len = Integer.parseInt(query.split("=")[1]);
347+
len = Integer.parseInt(qv);
343348
}
344349

350+
// if we get an exception past this point
351+
// we will rethrow it
352+
accepted = true;
353+
345354
OutputStream os = s.getOutputStream();
346355
os.write(responseHeaders().getBytes(US_ASCII));
347-
out.println(name + ": headers written, writing " + len + " body bytes");
356+
out.println(name + ": headers written, writing " + len + " body bytes");
348357
byte[] responseBytes = responseBody().getBytes(US_ASCII);
349-
for (int i = 0; i< len; i++) {
358+
for (int i = 0; i < len; i++) {
350359
os.write(responseBytes[i]);
351360
os.flush();
352361
}
353-
} catch (IOException e) {
354-
if (!closed)
355-
throw new UncheckedIOException("Unexpected", e);
362+
} catch (IOException | RuntimeException e) {
363+
if (!closed) {
364+
if (--maxUnexpected <= 0 || accepted) {
365+
if (e instanceof IOException io)
366+
throw new UncheckedIOException(io);
367+
else throw (RuntimeException) e;
368+
}
369+
out.println("ignoring unexpected exception: " + e);
370+
continue;
371+
}
356372
}
357373
}
358374
}

0 commit comments

Comments
 (0)