Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 17 additions & 18 deletions test/jdk/java/lang/ProcessBuilder/Basic.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
* 5026830 5023243 5070673 4052517 4811767 6192449 6397034 6413313
* 6464154 6523983 6206031 4960438 6631352 6631966 6850957 6850958
* 4947220 7018606 7034570 4244896 5049299 8003488 8054494 8058464
* 8067796 8224905 8263729 8265173 8272600 8231297 8282219
* 8067796 8224905 8263729 8265173 8272600 8231297 8282219 8368192
* @key intermittent
* @summary Basic tests for Process and Environment Variable code
* @modules java.base/java.lang:open
Expand Down Expand Up @@ -762,30 +762,29 @@ private static boolean matches(String str, String regex) {
return Pattern.compile(regex).matcher(str).find();
}

private static String matchAndExtract(String str, String regex) {
Matcher matcher = Pattern.compile(regex).matcher(str);
if (matcher.find()) {
return matcher.group();
} else {
return "";
}
// Return the string with the matching regex removed
private static String matchAndRemove(String str, String regex) {
return Pattern.compile(regex)
.matcher(str)
.replaceAll("");
}

/* Only used for Mac OS X --
* Mac OS X (may) add the variable __CF_USER_TEXT_ENCODING to an empty
* environment. The environment variable JAVA_MAIN_CLASS_<pid> may also
* be set in Mac OS X.
* Remove them both from the list of env variables
* Mac OS X (may) add the variables: __CF_USER_TEXT_ENCODING, JAVA_MAIN_CLASS_<pid>,
* and TMPDIR.
* Remove them from the list of env variables
*/
private static String removeMacExpectedVars(String vars) {
// Check for __CF_USER_TEXT_ENCODING
String cleanedVars = vars.replace("__CF_USER_TEXT_ENCODING="
+cfUserTextEncoding+",","");
String cleanedVars = matchAndRemove(vars,
"__CF_USER_TEXT_ENCODING=" + cfUserTextEncoding + ",");
// Check for JAVA_MAIN_CLASS_<pid>
String javaMainClassStr
= matchAndExtract(cleanedVars,
"JAVA_MAIN_CLASS_\\d+=Basic.JavaChild,");
return cleanedVars.replace(javaMainClassStr,"");
cleanedVars = matchAndRemove(cleanedVars,
"JAVA_MAIN_CLASS_\\d+=Basic.JavaChild,");
// Check and remove TMPDIR
cleanedVars = matchAndRemove(cleanedVars,
"TMPDIR=[^,]*,");
return cleanedVars;
}

/* Only used for AIX --
Expand Down