Skip to content

Commit 3b9059a

Browse files
committed
8290083: ResponseBodyBeforeError: AssertionError or SSLException: Unsupported or unrecognized SSL message
Reviewed-by: jpai
1 parent f42dab8 commit 3b9059a

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
@@ -346,7 +346,10 @@ protected ServerSocket newServerSocket() throws IOException {
346346

347347
@Override
348348
public void run() {
349+
int maxUnexpected = 10; // if we get there too often we may
350+
// want to reassess the diagnosis
349351
while (!closed) {
352+
boolean accepted = false;
350353
try (Socket s = ss.accept()) {
351354
out.print(name + ": got connection ");
352355
InputStream is = s.getInputStream();
@@ -357,26 +360,39 @@ public void run() {
357360
readRequestHeaders(is);
358361

359362
String query = uriPath.getRawQuery();
360-
assert query != null;
363+
if (query == null) {
364+
throw new IOException("expected query not found in: " + uriPath);
365+
}
361366
String qv = query.split("=")[1];
362367
int len;
363368
if (qv.equals("all")) {
364369
len = responseBody().getBytes(US_ASCII).length;
365370
} else {
366-
len = Integer.parseInt(query.split("=")[1]);
371+
len = Integer.parseInt(qv);
367372
}
368373

374+
// if we get an exception past this point
375+
// we will rethrow it
376+
accepted = true;
377+
369378
OutputStream os = s.getOutputStream();
370379
os.write(responseHeaders().getBytes(US_ASCII));
371-
out.println(name + ": headers written, writing " + len + " body bytes");
380+
out.println(name + ": headers written, writing " + len + " body bytes");
372381
byte[] responseBytes = responseBody().getBytes(US_ASCII);
373-
for (int i = 0; i< len; i++) {
382+
for (int i = 0; i < len; i++) {
374383
os.write(responseBytes[i]);
375384
os.flush();
376385
}
377-
} catch (IOException e) {
378-
if (!closed)
379-
throw new UncheckedIOException("Unexpected", e);
386+
} catch (IOException | RuntimeException e) {
387+
if (!closed) {
388+
if (--maxUnexpected <= 0 || accepted) {
389+
if (e instanceof IOException io)
390+
throw new UncheckedIOException(io);
391+
else throw (RuntimeException) e;
392+
}
393+
out.println("ignoring unexpected exception: " + e);
394+
continue;
395+
}
380396
}
381397
}
382398
}

0 commit comments

Comments
 (0)