Skip to content

Commit 74c4844

Browse files
authored
Avoid null value being converted to "null" string in environment (#1096)
If the CDT Variable is APPEND or PREPEND, and the incoming environment did not contain that variable name, the resulting environment would have null. For example, if PATH was not set on the incoming environment, and PATH was supposed to be prepended with /usr/bin, this method would have set PATH=/usr/bin:null This change ensures that the delimeter + null are not prended/appended when the incoming value is null.
1 parent 6f818cd commit 74c4844

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/envvar/EnvironmentVariableManager.java

+16-4
Original file line numberDiff line numberDiff line change
@@ -457,12 +457,24 @@ public void setEnvironment(Map<String, String> env, IBuildConfiguration config,
457457
case IEnvironmentVariable.ENVVAR_REPLACE:
458458
env.put(name, var.getValue());
459459
break;
460-
case IEnvironmentVariable.ENVVAR_APPEND:
461-
env.put(name, env.get(name) + var.getDelimiter() + var.getValue());
460+
case IEnvironmentVariable.ENVVAR_APPEND: {
461+
String oldValue = env.get(name);
462+
if (oldValue == null) {
463+
env.put(name, var.getValue());
464+
} else {
465+
env.put(name, oldValue + var.getDelimiter() + var.getValue());
466+
}
462467
break;
463-
case IEnvironmentVariable.ENVVAR_PREPEND:
464-
env.put(name, var.getValue() + var.getDelimiter() + env.get(name));
468+
}
469+
case IEnvironmentVariable.ENVVAR_PREPEND: {
470+
String oldValue = env.get(name);
471+
if (oldValue == null) {
472+
env.put(name, var.getValue());
473+
} else {
474+
env.put(name, var.getValue() + var.getDelimiter() + oldValue);
475+
}
465476
break;
477+
}
466478
case IEnvironmentVariable.ENVVAR_REMOVE:
467479
env.remove(name);
468480
break;

0 commit comments

Comments
 (0)