8368192: Test java/lang/ProcessBuilder/Basic.java#id0 fails with Exception: Stack trace

Reviewed-by: sgehwolf
Backport-of: 2b5b97b3cc44b34f1d3d2f2e9fd2fa545d769e3b
This commit is contained in:
Antonio Vieiro 2025-11-20 13:28:57 +00:00
parent 9b42765e21
commit 2df5d20266

View File

@ -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 8282219
* 8067796 8224905 8263729 8265173 8282219 8368192
* @key intermittent
* @summary Basic tests for Process and Environment Variable code
* @modules java.base/java.lang:open
@ -759,30 +759,29 @@ public class Basic {
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 --