From 62f552bc16e5e8442aad342182473412d24d0a62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillermo=20Guti=C3=A9rrez?= Date: Sat, 31 Oct 2020 09:19:54 +0100 Subject: [PATCH] Prevent BriefcaseException for trying to access a request's body when it's not present --- src/org/opendatakit/briefcase/reused/http/CommonsHttp.java | 2 +- src/org/opendatakit/briefcase/reused/http/Request.java | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/org/opendatakit/briefcase/reused/http/CommonsHttp.java b/src/org/opendatakit/briefcase/reused/http/CommonsHttp.java index 8824ef7d7..22550fcbd 100644 --- a/src/org/opendatakit/briefcase/reused/http/CommonsHttp.java +++ b/src/org/opendatakit/briefcase/reused/http/CommonsHttp.java @@ -152,7 +152,7 @@ private Response uncheckedExecute(Request request, Executor executor) } catch (IOException e) { throw new UncheckedIOException(e); } finally { - UncheckedFiles.closeInputStream(request.getBody()); + request.ifBody(UncheckedFiles::closeInputStream); if (request.multipartMessages != null) request.multipartMessages.stream() .map(MultipartMessage::getBody) diff --git a/src/org/opendatakit/briefcase/reused/http/Request.java b/src/org/opendatakit/briefcase/reused/http/Request.java index 98dd2f622..7068fc655 100644 --- a/src/org/opendatakit/briefcase/reused/http/Request.java +++ b/src/org/opendatakit/briefcase/reused/http/Request.java @@ -25,6 +25,7 @@ import java.util.Objects; import java.util.Optional; import java.util.function.BiConsumer; +import java.util.function.Consumer; import java.util.function.Function; import org.opendatakit.briefcase.reused.BriefcaseException; import org.slf4j.Logger; @@ -124,6 +125,10 @@ public InputStream getBody() { return body.orElseThrow(BriefcaseException::new); } + public void ifBody(Consumer consumer) { + body.ifPresent(consumer); + } + public boolean ignoreCookies() { return ignoreCookies; }