Skip to content

Commit

Permalink
ProcessFactory.java : envpToEnvMap() consider null envp
Browse files Browse the repository at this point in the history
  • Loading branch information
xu-chiheng committed Dec 6, 2022
1 parent ac64d4a commit ea79d13
Showing 1 changed file with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,17 @@ private static TreeMap<String, String> newEmptyEnvironment() {
return environment;
}

private static TreeMap<String, String> envpToEnvMap(String[] envp) {
private static TreeMap<String, String> getDefaultEnvironment() {
TreeMap<String, String> environment = newEmptyEnvironment();
Map<String, String> env = new ProcessBuilder().environment();
environment.putAll(env);
return environment;
}

private static TreeMap<String, String> envpToEnvMap(String[] envp) {
TreeMap<String, String> environment;
if (envp != null) {
environment = newEmptyEnvironment();
for (String envstring : envp) {
int eqlsign = envstring.indexOf('=');
if (eqlsign != -1) {
Expand All @@ -73,17 +81,12 @@ private static TreeMap<String, String> envpToEnvMap(String[] envp) {
// Silently ignore envstrings lacking the required `='.
}
}
} else {
environment = getDefaultEnvironment();
}
return environment;
}

private static TreeMap<String, String> getDefaultEnvironment() {
TreeMap<String, String> environment = newEmptyEnvironment();
Map<String, String> env = new ProcessBuilder().environment();
environment.putAll(env);
return environment;
}

private static void appendEnvMapComparison(StringBuilder sb, TreeMap<String, String> environmentA,
TreeMap<String, String> environmentB) {
TreeMap<String, String> environmentC = newEmptyEnvironment();
Expand Down

0 comments on commit ea79d13

Please sign in to comment.