Skip to content

Commit

Permalink
Handle null values
Browse files Browse the repository at this point in the history
  • Loading branch information
cherylking committed Jul 12, 2023
1 parent 01e6090 commit 11c2fdf
Showing 1 changed file with 14 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,7 @@ private void loadLibertyConfigFromProperties(Properties props) {
String suffix = key.substring(propType.getPrefix().length());
String value = (String) entry.getValue();
// Check the value for late property resolution with @{xxx} syntax.
value = handleLatePropertyResolution(value);
value = resolveLatePropertyReferences(value);

getLog().debug("Processing Liberty configuration from property with key "+key+" and value "+value);
switch (propType) {
Expand All @@ -825,17 +825,19 @@ private void loadLibertyConfigFromProperties(Properties props) {
}

// Search the value parameter for any properties referenced with @{xxx} syntax and replace those with their property value if defined.
private String handleLatePropertyResolution(String value) {
private String resolveLatePropertyReferences(String value) {
String returnValue = value;

Matcher m = LATE_PROP_PATTERN.matcher(value);
while (m.find()) {
String varName = m.group(1);
if (project.getProperties().containsKey(varName)) {
String replacementValue = project.getProperties().getProperty(varName);
if (replacementValue != null) {
returnValue = returnValue.replace("@{"+varName+"}", replacementValue);
getLog().debug("Replaced Liberty configuration property value @{"+varName+"} with value "+replacementValue);
if (value != null) {
Matcher m = LATE_PROP_PATTERN.matcher(value);
while (m.find()) {
String varName = m.group(1);
if (project.getProperties().containsKey(varName)) {
String replacementValue = project.getProperties().getProperty(varName);
if (replacementValue != null) {
returnValue = returnValue.replace("@{"+varName+"}", replacementValue);
getLog().debug("Replaced Liberty configuration property value @{"+varName+"} with value "+replacementValue);
}
}
}
}
Expand All @@ -848,7 +850,7 @@ protected Map<String,String> handleLatePropertyResolution(Map<String,String> pro
if (properties != null) {
propertiesResolved = new HashMap<String,String> ();
for (Map.Entry<String, String> entry : properties.entrySet()) {
String value = handleLatePropertyResolution(entry.getValue());
String value = resolveLatePropertyReferences(entry.getValue());
propertiesResolved.put(entry.getKey(), value);
}
}
Expand All @@ -860,7 +862,7 @@ protected List<String> handleLatePropertyResolution(List<String> properties) {
if (properties != null) {
propertiesResolved = new ArrayList<String> ();
for (String nextOption : properties) {
String value = handleLatePropertyResolution(nextOption);
String value = resolveLatePropertyReferences(nextOption);
propertiesResolved.add(value);
}
}
Expand Down

0 comments on commit 11c2fdf

Please sign in to comment.