From fd8c350e89cae34ce8ec871d0e842a84caa5ed33 Mon Sep 17 00:00:00 2001 From: MMeent Date: Tue, 3 Mar 2020 21:38:14 +0100 Subject: [PATCH 1/3] Revert try-with-resources for S3GzipCallable This would close the InputStream prematurely, failing on the scheduled uploads who expected an open stream. Note that as the upload continues after the return, therefore the zip-stream must not (yet) be closed in this context. Fixes JENKINS-60916 --- src/main/java/hudson/plugins/s3/callable/S3GzipCallable.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/hudson/plugins/s3/callable/S3GzipCallable.java b/src/main/java/hudson/plugins/s3/callable/S3GzipCallable.java index 39ede386..0d99b099 100644 --- a/src/main/java/hudson/plugins/s3/callable/S3GzipCallable.java +++ b/src/main/java/hudson/plugins/s3/callable/S3GzipCallable.java @@ -71,7 +71,8 @@ public String invoke(FilePath file) throws IOException, InterruptedException { final File localFile = gzipFile(file); Upload upload = null; - try (final InputStream gzippedStream = new FileInputStream(localFile)) { + try { + final InputStream gzippedStream = new FileInputStream(localFile) final ObjectMetadata metadata = buildMetadata(file); metadata.setContentEncoding("gzip"); metadata.setContentLength(localFile.length()); From 4c7b1cf61b80f6c1964363b35d969c6c05c24bea Mon Sep 17 00:00:00 2001 From: MMeent Date: Tue, 3 Mar 2020 21:38:58 +0100 Subject: [PATCH 2/3] Update S3GzipCallable.java semicolons --- src/main/java/hudson/plugins/s3/callable/S3GzipCallable.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/hudson/plugins/s3/callable/S3GzipCallable.java b/src/main/java/hudson/plugins/s3/callable/S3GzipCallable.java index 0d99b099..589e9feb 100644 --- a/src/main/java/hudson/plugins/s3/callable/S3GzipCallable.java +++ b/src/main/java/hudson/plugins/s3/callable/S3GzipCallable.java @@ -72,7 +72,7 @@ public String invoke(FilePath file) throws IOException, InterruptedException { Upload upload = null; try { - final InputStream gzippedStream = new FileInputStream(localFile) + final InputStream gzippedStream = new FileInputStream(localFile); final ObjectMetadata metadata = buildMetadata(file); metadata.setContentEncoding("gzip"); metadata.setContentLength(localFile.length()); From c1e7eb932ad85d51aeb7a8787c228dff75fcff02 Mon Sep 17 00:00:00 2001 From: MMeent Date: Wed, 4 Mar 2020 12:16:02 +0100 Subject: [PATCH 3/3] Add warning suppression and documentation. --- .../java/hudson/plugins/s3/callable/S3GzipCallable.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/hudson/plugins/s3/callable/S3GzipCallable.java b/src/main/java/hudson/plugins/s3/callable/S3GzipCallable.java index 589e9feb..16ebe5b8 100644 --- a/src/main/java/hudson/plugins/s3/callable/S3GzipCallable.java +++ b/src/main/java/hudson/plugins/s3/callable/S3GzipCallable.java @@ -66,12 +66,16 @@ public void progressChanged(ProgressEvent event) { } @Override - @SuppressFBWarnings("RV_RETURN_VALUE_IGNORED_BAD_PRACTICE") + @SuppressFBWarnings({"RV_RETURN_VALUE_IGNORED_BAD_PRACTICE","OBL_UNSATISFIED_OBLIGATION"}) public String invoke(FilePath file) throws IOException, InterruptedException { final File localFile = gzipFile(file); Upload upload = null; try { + // This stream is asynchronously used in startUploading, + // so we cannot use its AutoCloseable behaviour with a + // try-with-resources statement, as that would likely + // close the stream before the upload has succeeded. final InputStream gzippedStream = new FileInputStream(localFile); final ObjectMetadata metadata = buildMetadata(file); metadata.setContentEncoding("gzip");