Skip to content

Commit 78215ac

Browse files
authored
Unset config properties: System.getProperty should return default value or null (#10096)
Previously submitted as #10013 and reverted in #1094 Fixes #9885
1 parent e3034de commit 78215ac

File tree

4 files changed

+30
-7
lines changed

4 files changed

+30
-7
lines changed

dev/core/src/com/google/gwt/dev/cfg/ConfigurationProperties.java

+11
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,17 @@ public List<String> getStrings(String key) {
141141
return properties.get(key);
142142
}
143143

144+
/**
145+
* Returns all the values of a multi-valued configuration property, or null
146+
* if not found.
147+
*
148+
* <p>A single-valued and unset configuration property will be returned as a list
149+
* containing one null.
150+
*/
151+
public List<String> getStringsOrNull(String key) {
152+
return properties.get(key);
153+
}
154+
144155
/**
145156
* Reads a configuration property as a comma-separated list of strings.
146157
* It may be a single-valued or multi-valued property. If multi-valued,

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

+15-7
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
/**
@@ -74,21 +75,28 @@ public void endVisit(JPermutationDependentValue x, Context ctx) {
7475
}
7576

7677
private JExpression propertyValueExpression(JPermutationDependentValue x) {
77-
List<String> propertyValues = props.getConfigurationProperties().getStrings(x.getRequestedValue());
78-
79-
String propertyValue = propertyValues.isEmpty() ? null : Joiner.on(",").join(propertyValues);
80-
81-
if (propertyValue != null) {
78+
List<String> propertyValues = props.getConfigurationProperties()
79+
.getStringsOrNull(x.getRequestedValue());
80+
if (propertyValues != null) {
8281
// It is a configuration property.
83-
return program.getLiteral(x.getSourceInfo(), propertyValue);
82+
// If no values are set, propertyValues is either empty (multivalued properties)
83+
// or contains a single null (other properties).
84+
if (propertyValues.stream().anyMatch(Objects::nonNull)) {
85+
return program.getLiteral(x.getSourceInfo(),
86+
Joiner.on(",").skipNulls().join(propertyValues));
87+
}
88+
if (x.getDefaultValueExpression() != null) {
89+
return x.getDefaultValueExpression();
90+
}
91+
return program.getLiteralNull();
8492
}
8593

8694
if (isSoftPermutationProperty(x.getRequestedValue())) {
8795
JMethod method = getOrCreateSoftPropertyMethod(x.getSourceInfo(), x.getRequestedValue());
8896
return new JMethodCall(x.getSourceInfo(), null, method);
8997
}
9098

91-
propertyValue = commonPropertyAndBindingInfo.getPropertyValue(x.getRequestedValue());
99+
String propertyValue = commonPropertyAndBindingInfo.getPropertyValue(x.getRequestedValue());
92100

93101
if (propertyValue != null) {
94102
return program.getLiteral(x.getSourceInfo(), propertyValue);

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

+2
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,6 @@
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"/>
37+
<define-configuration-property name="multivaluedConfigPropertyUnset" is-multi-valued="true"/>
3638
</module>

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

+2
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,7 @@ 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"));
40+
assertNull(System.getProperty("configPropertyUnset"));
3941
}
4042
}

0 commit comments

Comments
 (0)