[java] Checking latch.await return value to detect timeout and throw an exception
@@ -115,7 +115,7 @@ public HttpResponse execute(HttpRequest req) throws UncheckedIOException {
queryPairs.add(URLEncoder.encode(name, UTF_8.toString()) + "=" + URLEncoder.encode(value, UTF_8.toString()));
} catch (UnsupportedEncodingException e) {
Thread.currentThread().interrupt();
- throw new RuntimeException(e);
+ throw new UncheckedIOException(e);
}
}));
if (!queryPairs.isEmpty()) {
@@ -149,7 +149,9 @@ public HttpResponse execute(HttpRequest req) throws UncheckedIOException {
}
try {
- latch.await(getConfig().readTimeout().toMillis(), MILLISECONDS);
+ if (!latch.await(getConfig().readTimeout().toMillis(), MILLISECONDS)) {
+ throw new UncheckedIOException(new IOException("Timed out waiting for response"));
+ }
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new RuntimeException(e);
