ppkarwasz commented on a change in pull request #742:
URL: https://github.com/apache/logging-log4j2/pull/742#discussion_r801300914



##########
File path: 
log4j-api/src/main/java/org/apache/logging/log4j/util/PropertiesUtil.java
##########
@@ -454,28 +472,36 @@ private synchronized void reload() {
             literal.clear();
             normalized.clear();
             tokenized.clear();
-            for (final PropertySource source : sources) {
-                source.forEach((key, value) -> {
-                    if (key != null && value != null) {
-                        literal.put(key, value);
-                        final List<CharSequence> tokens = 
PropertySource.Util.tokenize(key);
-                        if (tokens.isEmpty()) {
-                            
normalized.put(source.getNormalForm(Collections.singleton(key)), value);
-                        } else {
-                            normalized.put(source.getNormalForm(tokens), 
value);
-                            tokenized.put(tokens, value);
+            // 1. Collects all property keys from enumerable sources.
+            final Set<String> keys = new HashSet<>();
+            sources.stream()
+                   .map(PropertySource::getPropertyNames)
+                   .reduce(keys, (left, right) -> {
+                       left.addAll(right);
+                       return left;
+                   });
+            // 2. Fills the property caches. Sources with higher priority 
values don't override the previous ones.
+            keys.stream()
+                .filter(Objects::nonNull)
+                .forEach(key -> {
+                    final List<CharSequence> tokens = 
PropertySource.Util.tokenize(key);
+                    sources.forEach(source -> {
+                        final String value = source.getProperty(key);
+                        if (value != null) {
+                            literal.putIfAbsent(key, value);
+                            if (!tokens.isEmpty()) {
+                                tokenized.putIfAbsent(tokens, value);
+                            }
                         }
-                    }
+                        final CharSequence normalKey = 
source.getNormalForm(tokens);
+                        if (normalKey != null) {
+                            final String normalValue = 
source.getProperty(normalKey.toString());
+                            if (normalValue != null) {
+                                normalized.putIfAbsent(key, normalValue);
+                            }
+                        }
+                    });
                 });
-            }
-        }
-
-        private static boolean hasSystemProperty(final String key) {
-            try {
-                return System.getProperties().containsKey(key);
-            } catch (final SecurityException ignored) {
-                return false;
-            }

Review comment:
       System properties are resolved by the `SystemPropertiesPropertySource`.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to