From 41cfa132d2a2c76b14cf1c9240ad6a0405895ffd Mon Sep 17 00:00:00 2001 From: Spencer Gibb Date: Fri, 28 Aug 2015 15:27:21 -0600 Subject: [PATCH] fix possible NPE fixes gh-51 --- ...ironmentDecryptApplicationInitializer.java | 47 ++++++++++--------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/spring-cloud-context/src/main/java/org/springframework/cloud/bootstrap/encrypt/EnvironmentDecryptApplicationInitializer.java b/spring-cloud-context/src/main/java/org/springframework/cloud/bootstrap/encrypt/EnvironmentDecryptApplicationInitializer.java index 2048bc5f..c829247f 100644 --- a/spring-cloud-context/src/main/java/org/springframework/cloud/bootstrap/encrypt/EnvironmentDecryptApplicationInitializer.java +++ b/spring-cloud-context/src/main/java/org/springframework/cloud/bootstrap/encrypt/EnvironmentDecryptApplicationInitializer.java @@ -124,31 +124,32 @@ public class EnvironmentDecryptApplicationInitializer implements EnumerablePropertySource enumerable = (EnumerablePropertySource) source; for (String key : enumerable.getPropertyNames()) { - String value = source.getProperty(key).toString(); - if (value.startsWith("{cipher}")) { - value = value.substring("{cipher}".length()); - try { - value = encryptor.decrypt(value); - if (logger.isDebugEnabled()) { - logger.debug("Decrypted: key=" + key); + Object property = source.getProperty(key); + if (property != null) { + String value = property.toString(); + if (value.startsWith("{cipher}")) { + value = value.substring("{cipher}".length()); + try { + value = encryptor.decrypt(value); + if (logger.isDebugEnabled()) { + logger.debug("Decrypted: key=" + key); + } + } catch (Exception e) { + String message = "Cannot decrypt: key=" + key; + if (failOnError) { + throw new IllegalStateException(message, e); + } + if (logger.isDebugEnabled()) { + logger.warn(message, e); + } else { + logger.warn(message); + } + // Set value to empty to avoid making a password out of the + // cipher text + value = ""; } + overrides.put(key, value); } - catch (Exception e) { - String message = "Cannot decrypt: key=" + key; - if (failOnError) { - throw new IllegalStateException(message, e); - } - if (logger.isDebugEnabled()) { - logger.warn(message, e); - } - else { - logger.warn(message); - } - // Set value to empty to avoid making a password out of the - // cipher text - value = ""; - } - overrides.put(key, value); } }