Skip to content

Commit

Permalink
Unset config properties: use default value or fail with meaningful ex…
Browse files Browse the repository at this point in the history
…ception
  • Loading branch information
zbynek committed Oct 18, 2024
1 parent 32d07c8 commit 4a64e9d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

/**
Expand Down Expand Up @@ -76,7 +77,14 @@ public void endVisit(JPermutationDependentValue x, Context ctx) {
private JExpression propertyValueExpression(JPermutationDependentValue x) {
List<String> propertyValues = props.getConfigurationProperties().getStrings(x.getRequestedValue());

String propertyValue = propertyValues.isEmpty() ? null : Joiner.on(",").join(propertyValues);
if (!propertyValues.isEmpty() && propertyValues.stream().allMatch(Objects::isNull)) {
if (x.getDefaultValueExpression() != null) {
return x.getDefaultValueExpression();
}
throw new InternalCompilerException("No default set for configuration property '"
+ x.getRequestedValue() + "'");
}
String propertyValue = propertyValues.isEmpty() ? null : Joiner.on(",").skipNulls().join(propertyValues);

if (propertyValue != null) {
// It is a configuration property.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@
<set-property name="someOtherDynamicProperty" value="blue">
<when-property-is name="collapsedProperty" value="two"/>
</set-property>
<define-configuration-property name="configPropertyUnset" is-multi-valued="false"/>
</module>
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,6 @@ public void testBindingProperties() {
String expectedResult = "safari".equals(System.getProperty("user.agent")) ?
"InSafari" : "NotInSafari";
assertEquals(expectedResult, System.getProperty("someDynamicProperty"));
assertEquals("foo", System.getProperty("configPropertyUnset", "foo"));
}
}

0 comments on commit 4a64e9d

Please sign in to comment.