Skip to content

Commit fefa04d

Browse files
committed
Backport 2b5b97b3cc44b34f1d3d2f2e9fd2fa545d769e3b
1 parent f607e39 commit fefa04d

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 8282219
30+
* 8067796 8224905 8263729 8265173 8282219 8368192
3131
* @key intermittent
3232
* @summary Basic tests for Process and Environment Variable code
3333
* @modules java.base/java.lang:open
@@ -759,30 +759,29 @@ private static boolean matches(String str, String regex) {
759759
return Pattern.compile(regex).matcher(str).find();
760760
}
761761

762-
private static String matchAndExtract(String str, String regex) {
763-
Matcher matcher = Pattern.compile(regex).matcher(str);
764-
if (matcher.find()) {
765-
return matcher.group();
766-
} else {
767-
return "";
768-
}
762+
// Return the string with the matching regex removed
763+
private static String matchAndRemove(String str, String regex) {
764+
return Pattern.compile(regex)
765+
.matcher(str)
766+
.replaceAll("");
769767
}
770768

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

788787
/* Only used for AIX --

0 commit comments

Comments
 (0)