Skip to content

Commit 2b5b97b

Browse files
committed
8368192: Test java/lang/ProcessBuilder/Basic.java#id0 fails with Exception: Stack trace
Reviewed-by: phh Backport-of: 218e82c875237f82a649a214c72d925a5ebf188c
1 parent cba64ce commit 2b5b97b

File tree

1 file changed

+17
-18
lines changed

1 file changed

+17
-18
lines changed

test/jdk/java/lang/ProcessBuilder/Basic.java

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
* 5026830 5023243 5070673 4052517 4811767 6192449 6397034 6413313
2828
* 6464154 6523983 6206031 4960438 6631352 6631966 6850957 6850958
2929
* 4947220 7018606 7034570 4244896 5049299 8003488 8054494 8058464
30-
* 8067796 8224905 8263729 8265173 8272600 8231297 8282219
30+
* 8067796 8224905 8263729 8265173 8272600 8231297 8282219 8368192
3131
* @key intermittent
3232
* @summary Basic tests for Process and Environment Variable code
3333
* @modules java.base/java.lang:open
@@ -762,30 +762,29 @@ private static boolean matches(String str, String regex) {
762762
return Pattern.compile(regex).matcher(str).find();
763763
}
764764

765-
private static String matchAndExtract(String str, String regex) {
766-
Matcher matcher = Pattern.compile(regex).matcher(str);
767-
if (matcher.find()) {
768-
return matcher.group();
769-
} else {
770-
return "";
771-
}
765+
// Return the string with the matching regex removed
766+
private static String matchAndRemove(String str, String regex) {
767+
return Pattern.compile(regex)
768+
.matcher(str)
769+
.replaceAll("");
772770
}
773771

774772
/* Only used for Mac OS X --
775-
* Mac OS X (may) add the variable __CF_USER_TEXT_ENCODING to an empty
776-
* environment. The environment variable JAVA_MAIN_CLASS_<pid> may also
777-
* be set in Mac OS X.
778-
* Remove them both from the list of env variables
773+
* Mac OS X (may) add the variables: __CF_USER_TEXT_ENCODING, JAVA_MAIN_CLASS_<pid>,
774+
* and TMPDIR.
775+
* Remove them from the list of env variables
779776
*/
780777
private static String removeMacExpectedVars(String vars) {
781778
// Check for __CF_USER_TEXT_ENCODING
782-
String cleanedVars = vars.replace("__CF_USER_TEXT_ENCODING="
783-
+cfUserTextEncoding+",","");
779+
String cleanedVars = matchAndRemove(vars,
780+
"__CF_USER_TEXT_ENCODING=" + cfUserTextEncoding + ",");
784781
// Check for JAVA_MAIN_CLASS_<pid>
785-
String javaMainClassStr
786-
= matchAndExtract(cleanedVars,
787-
"JAVA_MAIN_CLASS_\\d+=Basic.JavaChild,");
788-
return cleanedVars.replace(javaMainClassStr,"");
782+
cleanedVars = matchAndRemove(cleanedVars,
783+
"JAVA_MAIN_CLASS_\\d+=Basic.JavaChild,");
784+
// Check and remove TMPDIR
785+
cleanedVars = matchAndRemove(cleanedVars,
786+
"TMPDIR=[^,]*,");
787+
return cleanedVars;
789788
}
790789

791790
/* Only used for AIX --

0 commit comments

Comments
 (0)