fix NPE in PropertyPlaceHolder
This commit is contained in:
parent
2b26886b17
commit
969f86baae
3 changed files with 24 additions and 2 deletions
|
@ -46,6 +46,9 @@ public class PropertyPlaceholder {
|
|||
protected String parseStringValue(String value,
|
||||
PlaceholderResolver placeholderResolver,
|
||||
Set<String> visitedPlaceholders) {
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
StringBuilder sb = new StringBuilder(value);
|
||||
int startIndex = value.indexOf(this.placeholderPrefix);
|
||||
while (startIndex != -1) {
|
||||
|
@ -53,8 +56,7 @@ public class PropertyPlaceholder {
|
|||
if (endIndex != -1) {
|
||||
String placeholder = sb.substring(startIndex + this.placeholderPrefix.length(), endIndex);
|
||||
if (!visitedPlaceholders.add(placeholder)) {
|
||||
throw new IllegalArgumentException(
|
||||
"Circular placeholder reference '" + placeholder + "' in property definitions");
|
||||
throw new IllegalArgumentException("Circular placeholder reference '" + placeholder + "' in property definitions");
|
||||
}
|
||||
placeholder = parseStringValue(placeholder, placeholderResolver, visitedPlaceholders);
|
||||
int defaultValueIdx = placeholder.indexOf(':');
|
||||
|
|
|
@ -23,6 +23,7 @@ import java.util.Map;
|
|||
import java.util.concurrent.TimeUnit;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/**
|
||||
|
@ -116,6 +117,15 @@ public class SettingsTest {
|
|||
assertEquals(LocalDate.now().getYear(), Integer.parseInt(settings.get("date")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPropertyReplaceNull() {
|
||||
Settings settings = Settings.settingsBuilder()
|
||||
.put("null", null)
|
||||
.replacePropertyPlaceholders()
|
||||
.build();
|
||||
assertNull(settings.get("null"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSystemEnvironment() {
|
||||
Settings settings = Settings.settingsBuilder()
|
||||
|
|
|
@ -13,6 +13,7 @@ import java.util.Map;
|
|||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class SettingsTest {
|
||||
|
@ -89,6 +90,15 @@ public class SettingsTest {
|
|||
assertEquals(LocalDate.now().getYear(), Integer.parseInt(settings.get("date")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPropertyReplaceNull() {
|
||||
Settings settings = Settings.settingsBuilder()
|
||||
.put("null", null)
|
||||
.replacePropertyPlaceholders()
|
||||
.build();
|
||||
assertNull(settings.get("null"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSystemEnvironment() {
|
||||
Settings settings = Settings.settingsBuilder()
|
||||
|
|
Loading…
Reference in a new issue