You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jmeter.apache.org by vl...@apache.org on 2023/04/30 06:21:02 UTC

[jmeter] 02/02: test: capture stderr in KeyToolUtils explicitly

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

vladimirsitnikov pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jmeter.git

commit 5020590c2dd6564e87cc2295e0090d2c6526c436
Author: Vladimir Sitnikov <si...@gmail.com>
AuthorDate: Mon Oct 31 11:49:43 2022 +0300

    test: capture stderr in KeyToolUtils explicitly
    
    By default SystemCommand redirects stderr to stdout in case stdErr hander was not set,
    which breaks output parsing when extra messages appear unexpectedly
    
    One of such messages is "Picked up _JAVA_OPTIONS: ..."
---
 .../main/java/org/apache/jorphan/exec/KeyToolUtils.java    | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/src/jorphan/src/main/java/org/apache/jorphan/exec/KeyToolUtils.java b/src/jorphan/src/main/java/org/apache/jorphan/exec/KeyToolUtils.java
index b7a5d34b4c..bef18bfbf5 100644
--- a/src/jorphan/src/main/java/org/apache/jorphan/exec/KeyToolUtils.java
+++ b/src/jorphan/src/main/java/org/apache/jorphan/exec/KeyToolUtils.java
@@ -421,8 +421,11 @@ public class KeyToolUtils {
             InputStream input, OutputStream output, String ... parameters)
             throws IOException {
         final File workingDir = keystore.getParentFile();
+        ByteArrayOutputStream stdErr = new ByteArrayOutputStream();
+        // If we omit stderr, then SystemCommand redirects stderr to stdout, and it might break keytool output
+        // with message like "Picked up _JAVA_OPTIONS: ..."
         final SystemCommand nativeCommand =
-                new SystemCommand(workingDir, 0L, 0, null, input, output, null);
+                new SystemCommand(workingDir, 0L, 0, null, input, output, stdErr);
         final List<String> arguments = new ArrayList<>();
         arguments.add(getKeyToolPath());
         arguments.add(command);
@@ -436,7 +439,14 @@ public class KeyToolUtils {
         arguments.add(alias);
         Collections.addAll(arguments, parameters);
 
-        runNativeCommand(nativeCommand, arguments);
+        try {
+            runNativeCommand(nativeCommand, arguments);
+        } catch (IOException e) {
+            if (stdErr.size() > 0) {
+                e.addSuppressed(new IOException("standard error (stderr) was: " + stdErr));
+            }
+            throw e;
+        }
     }
 
     /**