From ea79d1342144965f401a41483e6b11fb393accb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E6=8C=81=E6=81=92=20Xu=20Chiheng?= Date: Wed, 7 Dec 2022 03:14:10 +0800 Subject: [PATCH] ProcessFactory.java : envpToEnvMap() consider null envp --- .../cdt/utils/spawner/ProcessFactory.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/core/org.eclipse.cdt.core.native/src/org/eclipse/cdt/utils/spawner/ProcessFactory.java b/core/org.eclipse.cdt.core.native/src/org/eclipse/cdt/utils/spawner/ProcessFactory.java index 5fd5dce9ac1..addd040267a 100644 --- a/core/org.eclipse.cdt.core.native/src/org/eclipse/cdt/utils/spawner/ProcessFactory.java +++ b/core/org.eclipse.cdt.core.native/src/org/eclipse/cdt/utils/spawner/ProcessFactory.java @@ -62,9 +62,17 @@ private static TreeMap newEmptyEnvironment() { return environment; } - private static TreeMap envpToEnvMap(String[] envp) { + private static TreeMap getDefaultEnvironment() { TreeMap environment = newEmptyEnvironment(); + Map env = new ProcessBuilder().environment(); + environment.putAll(env); + return environment; + } + + private static TreeMap envpToEnvMap(String[] envp) { + TreeMap environment; if (envp != null) { + environment = newEmptyEnvironment(); for (String envstring : envp) { int eqlsign = envstring.indexOf('='); if (eqlsign != -1) { @@ -73,17 +81,12 @@ private static TreeMap envpToEnvMap(String[] envp) { // Silently ignore envstrings lacking the required `='. } } + } else { + environment = getDefaultEnvironment(); } return environment; } - private static TreeMap getDefaultEnvironment() { - TreeMap environment = newEmptyEnvironment(); - Map env = new ProcessBuilder().environment(); - environment.putAll(env); - return environment; - } - private static void appendEnvMapComparison(StringBuilder sb, TreeMap environmentA, TreeMap environmentB) { TreeMap environmentC = newEmptyEnvironment();