Skip to content

Commit aa2506f

Browse files
committed
add lazy property initialization api to SystemPropertiesSupport
1 parent 83326c6 commit aa2506f

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/SystemPropertiesSupport.java

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ protected SystemPropertiesSupport() {
8484
properties = new Properties();
8585
savedProperties = new HashMap<>();
8686
readOnlySavedProperties = Collections.unmodifiableMap(savedProperties);
87+
lazyRuntimeValues = new HashMap<>();
8788

8889
for (String key : HOSTED_PROPERTIES) {
8990
String value = System.getProperty(key);
@@ -116,13 +117,12 @@ protected SystemPropertiesSupport() {
116117
initializeProperty("java.awt.printerjob", System.getProperty("java.awt.printerjob"));
117118
}
118119

119-
lazyRuntimeValues = new HashMap<>();
120-
lazyRuntimeValues.put("user.name", this::userName);
121-
lazyRuntimeValues.put("user.home", this::userHome);
122-
lazyRuntimeValues.put("user.dir", this::userDir);
123-
lazyRuntimeValues.put("java.io.tmpdir", this::tmpdirValue);
124-
lazyRuntimeValues.put("os.version", this::osVersionValue);
125-
lazyRuntimeValues.put("java.vm.version", VM::getVersion);
120+
initializeLazyProperty("user.name", this::userName);
121+
initializeLazyProperty("user.home", this::userHome);
122+
initializeLazyProperty("user.dir", this::userDir);
123+
initializeLazyProperty("java.io.tmpdir", this::tmpdirValue);
124+
initializeLazyProperty("os.version", this::osVersionValue);
125+
initializeLazyProperty("java.vm.version", VM::getVersion);
126126
}
127127

128128
private void ensureFullyInitialized() {
@@ -176,6 +176,14 @@ public void initializeProperty(String key, String value) {
176176
properties.setProperty(key, value);
177177
}
178178

179+
/**
180+
* Lazily initializes a property at runtime when it is first requested, based on the supplier's
181+
* return value.
182+
*/
183+
public void initializeLazyProperty(String key, Supplier<String> value) {
184+
lazyRuntimeValues.put(key, value);
185+
}
186+
179187
public String setProperty(String key, String value) {
180188
/*
181189
* The return value of setProperty is the previous value of the key, so we need to ensure

0 commit comments

Comments
 (0)