Skip to content

Commit

Permalink
RemoteFTempl: InputStream.close() in the finally
Browse files Browse the repository at this point in the history
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**
  • Loading branch information
artembilan authored and garyrussell committed Oct 5, 2018
1 parent 8a7adb8 commit 9e9fa2c
Showing 1 changed file with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2017 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.
Expand Down Expand Up @@ -391,11 +391,18 @@ public boolean get(Message<?> message, InputStreamCallback callback) {
@Override
public boolean get(final String remotePath, final InputStreamCallback callback) {
Assert.notNull(remotePath, "'remotePath' cannot be null");
return this.execute(session -> {
InputStream inputStream = session.readRaw(remotePath);
callback.doWithInputStream(inputStream);
inputStream.close();
return session.finalizeRaw();
return execute(session -> {
InputStream inputStream = null;
try {
inputStream = session.readRaw(remotePath);
callback.doWithInputStream(inputStream);
return session.finalizeRaw();
}
finally {
if (inputStream != null) {
inputStream.close();
}
}
});
}

Expand Down

0 comments on commit 9e9fa2c

Please sign in to comment.