Skip to content

Commit 4a64e9d

Browse files
committed
Unset config properties: use default value or fail with meaningful exception
1 parent 32d07c8 commit 4a64e9d

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

dev/core/src/com/google/gwt/dev/jjs/impl/ResolvePermutationDependentValues.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import java.util.Collection;
4848
import java.util.List;
4949
import java.util.Map;
50+
import java.util.Objects;
5051
import java.util.Set;
5152

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

79-
String propertyValue = propertyValues.isEmpty() ? null : Joiner.on(",").join(propertyValues);
80+
if (!propertyValues.isEmpty() && propertyValues.stream().allMatch(Objects::isNull)) {
81+
if (x.getDefaultValueExpression() != null) {
82+
return x.getDefaultValueExpression();
83+
}
84+
throw new InternalCompilerException("No default set for configuration property '"
85+
+ x.getRequestedValue() + "'");
86+
}
87+
String propertyValue = propertyValues.isEmpty() ? null : Joiner.on(",").skipNulls().join(propertyValues);
8088

8189
if (propertyValue != null) {
8290
// It is a configuration property.

user/test/com/google/gwt/dev/jjs/SystemGetPropertyTest.gwt.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,5 @@
3333
<set-property name="someOtherDynamicProperty" value="blue">
3434
<when-property-is name="collapsedProperty" value="two"/>
3535
</set-property>
36+
<define-configuration-property name="configPropertyUnset" is-multi-valued="false"/>
3637
</module>

user/test/com/google/gwt/dev/jjs/test/SystemGetPropertyTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,6 @@ public void testBindingProperties() {
3636
String expectedResult = "safari".equals(System.getProperty("user.agent")) ?
3737
"InSafari" : "NotInSafari";
3838
assertEquals(expectedResult, System.getProperty("someDynamicProperty"));
39+
assertEquals("foo", System.getProperty("configPropertyUnset", "foo"));
3940
}
4041
}

0 commit comments

Comments
 (0)