@@ -87,6 +87,7 @@ protected SystemPropertiesSupport() {
87
87
properties = new Properties ();
88
88
savedProperties = new HashMap <>();
89
89
readOnlySavedProperties = Collections .unmodifiableMap (savedProperties );
90
+ lazyRuntimeValues = new HashMap <>();
90
91
91
92
for (String key : HOSTED_PROPERTIES ) {
92
93
String value = System .getProperty (key );
@@ -114,19 +115,18 @@ protected SystemPropertiesSupport() {
114
115
initializeProperty ("java.awt.printerjob" , System .getProperty ("java.awt.printerjob" ));
115
116
}
116
117
117
- lazyRuntimeValues = new HashMap <>();
118
- lazyRuntimeValues .put ("user.name" , this ::userName );
119
- lazyRuntimeValues .put ("user.home" , this ::userHome );
120
- lazyRuntimeValues .put ("user.dir" , this ::userDir );
121
- lazyRuntimeValues .put ("java.io.tmpdir" , this ::tmpdirValue );
122
- lazyRuntimeValues .put ("os.version" , this ::osVersionValue );
123
- lazyRuntimeValues .put ("java.vm.version" , VM ::getVersion );
118
+ initializeLazyProperty ("user.name" , this ::userName );
119
+ initializeLazyProperty ("user.home" , this ::userHome );
120
+ initializeLazyProperty ("user.dir" , this ::userDir );
121
+ initializeLazyProperty ("java.io.tmpdir" , this ::tmpdirValue );
122
+ initializeLazyProperty ("os.version" , this ::osVersionValue );
123
+ initializeLazyProperty ("java.vm.version" , VM ::getVersion );
124
124
125
125
String targetName = System .getProperty ("svm.targetName" );
126
126
if (targetName != null ) {
127
127
initializeProperty ("os.name" , targetName );
128
128
} else {
129
- lazyRuntimeValues . put ("os.name" , this ::osNameValue );
129
+ initializeLazyProperty ("os.name" , this ::osNameValue );
130
130
}
131
131
132
132
String targetArch = System .getProperty ("svm.targetArch" );
@@ -188,6 +188,14 @@ public void initializeProperty(String key, String value) {
188
188
properties .setProperty (key , value );
189
189
}
190
190
191
+ /**
192
+ * Lazily initializes a property at runtime when it is first requested, based on the supplier's
193
+ * return value.
194
+ */
195
+ public void initializeLazyProperty (String key , Supplier <String > value ) {
196
+ lazyRuntimeValues .put (key , value );
197
+ }
198
+
191
199
public String setProperty (String key , String value ) {
192
200
/*
193
201
* The return value of setProperty is the previous value of the key, so we need to ensure
0 commit comments