@@ -84,6 +84,7 @@ protected SystemPropertiesSupport() {
84
84
properties = new Properties ();
85
85
savedProperties = new HashMap <>();
86
86
readOnlySavedProperties = Collections .unmodifiableMap (savedProperties );
87
+ lazyRuntimeValues = new HashMap <>();
87
88
88
89
for (String key : HOSTED_PROPERTIES ) {
89
90
String value = System .getProperty (key );
@@ -116,13 +117,12 @@ protected SystemPropertiesSupport() {
116
117
initializeProperty ("java.awt.printerjob" , System .getProperty ("java.awt.printerjob" ));
117
118
}
118
119
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 );
126
126
}
127
127
128
128
private void ensureFullyInitialized () {
@@ -176,6 +176,14 @@ public void initializeProperty(String key, String value) {
176
176
properties .setProperty (key , value );
177
177
}
178
178
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
+
179
187
public String setProperty (String key , String value ) {
180
188
/*
181
189
* The return value of setProperty is the previous value of the key, so we need to ensure
0 commit comments