Skip to content

Commit ef9c760

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 1fe22ea commit ef9c760

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2013-2016 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.
@@ -399,11 +399,19 @@ public boolean get(final String remotePath, final InputStreamCallback callback)
399399

400400
@Override
401401
public Boolean doInSession(Session<F> session) throws IOException {
402-
InputStream inputStream = session.readRaw(remotePath);
403-
callback.doWithInputStream(inputStream);
404-
inputStream.close();
405-
return session.finalizeRaw();
402+
InputStream inputStream = null;
403+
try {
404+
inputStream = session.readRaw(remotePath);
405+
callback.doWithInputStream(inputStream);
406+
return session.finalizeRaw();
407+
}
408+
finally {
409+
if (inputStream != null) {
410+
inputStream.close();
411+
}
412+
}
406413
}
414+
407415
});
408416
}
409417

0 commit comments

Comments
 (0)