#1103 java.lang.NullPointerException (#1104)

java.lang.NullPointerException while decrypting due to value is null and still looking for cipher string. #1103
This commit is contained in:
ramaiahkk
2018-08-06 12:51:43 -04:00
committed by Ryan Baxter
parent f0ea304a87
commit e380b83026
2 changed files with 15 additions and 2 deletions

View File

@@ -64,8 +64,8 @@ public class CipherEnvironmentEncryptor implements EnvironmentEncryptor {
for (Map.Entry<Object, Object> entry : new LinkedHashSet<>(map.entrySet())) {
Object key = entry.getKey();
String name = key.toString();
String value = entry.getValue().toString();
if (value.startsWith("{cipher}")) {
if(entry.getValue() != null && entry.getValue().toString().startsWith("{cipher}")){
String value = entry.getValue().toString();
map.remove(key);
try {
value = value.substring("{cipher}".length());

View File

@@ -90,5 +90,18 @@ public class CipherEnvironmentEncryptorTests {
assertEquals(secret, this.encryptor.decrypt(environment).getPropertySources()
.get(0).getSource().get(environment.getName()));
}
@Test
public void shouldBeAbleToUseNullAsPropertyValue() {
// when
Environment environment = new Environment("name", "profile", "label");
environment.add(new PropertySource("a",
Collections.<Object, Object>singletonMap(environment.getName(),
null)));
// then
assertEquals(null, this.encryptor.decrypt(environment).getPropertySources()
.get(0).getSource().get(environment.getName()));
}
}