Skip to content

Commit 3644c05

Browse files
artembilangaryrussell
authored andcommitted
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**
1 parent d9f0672 commit 3644c05

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

spring-integration-file/src/main/java/org/springframework/integration/file/remote/RemoteFileTemplate.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2013-2017 the original author or authors.
2+
* Copyright 2013-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -391,11 +391,18 @@ public boolean get(Message<?> message, InputStreamCallback callback) {
391391
@Override
392392
public boolean get(final String remotePath, final InputStreamCallback callback) {
393393
Assert.notNull(remotePath, "'remotePath' cannot be null");
394-
return this.execute(session -> {
395-
InputStream inputStream = session.readRaw(remotePath);
396-
callback.doWithInputStream(inputStream);
397-
inputStream.close();
398-
return session.finalizeRaw();
394+
return execute(session -> {
395+
InputStream inputStream = null;
396+
try {
397+
inputStream = session.readRaw(remotePath);
398+
callback.doWithInputStream(inputStream);
399+
return session.finalizeRaw();
400+
}
401+
finally {
402+
if (inputStream != null) {
403+
inputStream.close();
404+
}
405+
}
399406
});
400407
}
401408

0 commit comments

Comments
 (0)