From 5dbcc8ec2193beb29b99dee558e02322ca0ce6ff Mon Sep 17 00:00:00 2001 From: Andrew Eidsness Date: Wed, 28 Aug 2013 16:39:51 -0400 Subject: [PATCH] Bug 415789: NPE in ScannerConfigBuilder An implementation of IEnvironmentVariable is returning null for its key or value. The javadoc on this interface doesn't mention null, which I guess makes it a valid value. This patch checks the result before trying to put it into an instance of java.util.Properties. Change-Id: Ic04ddd72dfb558ca403b549b64847c3437971407 Signed-off-by: Andrew Eidsness Reviewed-on: https://git.eclipse.org/r/15820 Reviewed-by: Andrew Gvozdev IP-Clean: Andrew Gvozdev Tested-by: Andrew Gvozdev --- .../build/core/scannerconfig/ScannerConfigBuilder.java | 9 +++++++-- .../IConfigurationEnvironmentVariableSupplier.java | 2 +- .../cdt/core/envvar/IEnvironmentVariableManager.java | 5 +++-- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/build/core/scannerconfig/ScannerConfigBuilder.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/build/core/scannerconfig/ScannerConfigBuilder.java index 78099dbd610..4def2747bbd 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/build/core/scannerconfig/ScannerConfigBuilder.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/build/core/scannerconfig/ScannerConfigBuilder.java @@ -171,8 +171,13 @@ public class ScannerConfigBuilder extends ACBuilder { ICConfigurationDescription cfgDes = ManagedBuildManager.getDescriptionForConfiguration(cfg); IEnvironmentVariableManager mngr = CCorePlugin.getDefault().getBuildEnvironmentManager(); IEnvironmentVariable[] vars = mngr.getVariables(cfgDes, true); - for(int i = 0; i < vars.length; i++){ - envProps.setProperty(vars[i].getName(), vars[i].getValue()); + + for(int i = 0; i < vars.length; i++) { + if (vars[i] != null + && vars[i].getName() != null) { + String value = vars[i].getValue(); + envProps.setProperty(vars[i].getName(), value == null ? "" : value); + } } return envProps; diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/envvar/IConfigurationEnvironmentVariableSupplier.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/envvar/IConfigurationEnvironmentVariableSupplier.java index 2ad85459956..a6c5760f813 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/envvar/IConfigurationEnvironmentVariableSupplier.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/envvar/IConfigurationEnvironmentVariableSupplier.java @@ -50,7 +50,7 @@ public interface IConfigurationEnvironmentVariableSupplier { * and the provider in turn calls that supplier again. Also the supplier should not know anything * about the environment variables defined for the higher levels. * @return The array of IBuildEnvironmentVariable that represents the environment variables. - * If the array contains any {@code null} it will be ignored. + * The array may contain {@code null} values. */ IBuildEnvironmentVariable[] getVariables(IConfiguration configuration, IEnvironmentVariableProvider provider); } diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/envvar/IEnvironmentVariableManager.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/envvar/IEnvironmentVariableManager.java index 70f0d7197a0..7daabcaa068 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/envvar/IEnvironmentVariableManager.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/envvar/IEnvironmentVariableManager.java @@ -29,7 +29,7 @@ public interface IEnvironmentVariableManager{ * * * @return the reference to the IBuildEnvironmentVariable interface representing - * the variable of a given name + * the variable of a given name or null * @param name environment variable name * if environment variable names are case insensitive in the current OS, * the environment variable provider will query the getVariable method of suppliers always @@ -52,7 +52,8 @@ public interface IEnvironmentVariableManager{ * the environment variable provider will remove the duplicates of the variables if their names * differ only by case * - * @return the array of IBuildEnvironmentVariable that represents the environment variables + * @return the array of IBuildEnvironmentVariable that represents the environment variables (the + * array may contain null values) */ public IEnvironmentVariable[] getVariables(ICConfigurationDescription cfg, boolean resolveMacros);