java.lang.NullPointerException while decrypting due to value is null and still looking for cipher string. #1103
This commit is contained in:
@@ -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());
|
||||
|
||||
@@ -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()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user