From ef9c7609d517bca143f7f5dcd416a7802c125eb6 Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Fri, 5 Oct 2018 12:02:21 -0400 Subject: [PATCH] RemoteFTempl: InputStream.close() in the finally If exception happens in the `callback.doWithInputStream(inputStream)`, we don't close the `inputStream = session.readRaw(remotePath)`. * Move the `InputStream.close()` to the `finally` block of the `SessionCallback` action in the `RemoteFileTemplate.get()` **Cherry-pick to 5.0.x and 4.3.x** --- .../file/remote/RemoteFileTemplate.java | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/spring-integration-file/src/main/java/org/springframework/integration/file/remote/RemoteFileTemplate.java b/spring-integration-file/src/main/java/org/springframework/integration/file/remote/RemoteFileTemplate.java index 46d1a1af3d..380605ea5d 100644 --- a/spring-integration-file/src/main/java/org/springframework/integration/file/remote/RemoteFileTemplate.java +++ b/spring-integration-file/src/main/java/org/springframework/integration/file/remote/RemoteFileTemplate.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2016 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -399,11 +399,19 @@ public class RemoteFileTemplate implements RemoteFileOperations, Initializ @Override public Boolean doInSession(Session session) throws IOException { - InputStream inputStream = session.readRaw(remotePath); - callback.doWithInputStream(inputStream); - inputStream.close(); - return session.finalizeRaw(); + InputStream inputStream = null; + try { + inputStream = session.readRaw(remotePath); + callback.doWithInputStream(inputStream); + return session.finalizeRaw(); + } + finally { + if (inputStream != null) { + inputStream.close(); + } + } } + }); }