This is an automated email from the ASF dual-hosted git repository.

lgoldstein pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mina-sshd.git

commit 8415ed4a86b6c64cfae36a0dcd77542d498caff4
Author: Lyor Goldstein <lgoldst...@apache.org>
AuthorDate: Thu Aug 27 08:45:22 2020 +0300

    [SSHD-1064] Fixed ClientSession#executeRemoteCommand handling of STDERR in 
case of exception to behave according to its documentation
---
 CHANGES.md                                                 |  1 +
 .../java/org/apache/sshd/client/session/ClientSession.java | 14 ++++++++------
 2 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/CHANGES.md b/CHANGES.md
index 7470f94..bf19bdd 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -25,6 +25,7 @@ or `-key-file` command line option.
 * [SSHD-1042](https://issues.apache.org/jira/browse/SSHD-1042) Added more 
callbacks to SftpEventListener
 * [SSHD-1040](https://issues.apache.org/jira/browse/SSHD-1040) Make server key 
available after KEX completed.
 * [SSHD-1060](https://issues.apache.org/jira/browse/SSHD-1060) Do not store 
logger level in fields.
+* [SSHD-1064](https://issues.apache.org/jira/browse/SSHD-1064) Fixed 
`ClientSession#executeRemoteCommand` handling of STDERR in case of exception to 
behave according to its documentation
 
 ## Behavioral changes and enhancements
 
diff --git 
a/sshd-core/src/main/java/org/apache/sshd/client/session/ClientSession.java 
b/sshd-core/src/main/java/org/apache/sshd/client/session/ClientSession.java
index eb5b508..075d026 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/session/ClientSession.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/session/ClientSession.java
@@ -209,13 +209,15 @@ public interface ClientSession
      */
     default String executeRemoteCommand(String command) throws IOException {
         try (ByteArrayOutputStream stderr = new ByteArrayOutputStream()) {
-            String response = executeRemoteCommand(command, stderr, 
StandardCharsets.US_ASCII);
-            if (stderr.size() > 0) {
-                String errorMessage = 
stderr.toString(StandardCharsets.US_ASCII.name());
-                throw new RemoteException("Error reported from remote 
command='" + command, new ServerException(errorMessage));
+            try {
+                return executeRemoteCommand(command, stderr, 
StandardCharsets.US_ASCII);
+            } finally {
+                if (stderr.size() > 0) {
+                    String errorMessage = 
stderr.toString(StandardCharsets.US_ASCII.name());
+                    throw new RemoteException(
+                            "Error reported from remote command=" + command, 
new ServerException(errorMessage));
+                }
             }
-
-            return response;
         }
     }
 

Reply via email to