bmhm commented on a change in pull request #240:
URL: https://github.com/apache/shiro/pull/240#discussion_r439935634



##########
File path: 
config/ogdl/src/main/java/org/apache/shiro/config/ogdl/ReflectionBuilder.java
##########
@@ -290,7 +293,9 @@ private String parseBeanId(String lhs) {
         }
 
         //SHIRO-413: init method must be called for constructed objects that 
are Initializable
-        LifecycleUtils.init(objects.values());
+        //SHIRO-778: onInit method on AuthenticatingRealm is called twice
+        objects.keySet().stream().filter(key -> 
!Optional.ofNullable(kvPairs).orElseGet(HashMap::new).keySet().contains(key))

Review comment:
       I see another issue with this line. You are using `HashMap::new`. Let's 
just pretend you are following my comment to remove the overhead of 
instantiating the map for each key. We might have a line like this:
   
   `Map kvPairsToCheck = Optional.ofNullable(kvPairs).orElseGet(HashMap::new)`.
   
   If you expect the devs to modify this map in a later commit, please do not 
use `HashMap::new` which is prone to `ConcurrentModificationException`. A lot 
of apache projects prohibit it's use via checkstyle for this reason.
   
   If you do not expect devs to modify this map in later commits, you might as 
well use 
[`Collections::emptyMap`](https://docs.oracle.com/javase/8/docs/api/java/util/Collections.html#emptyMap--),
 which will hint the dev that this map is going to stay empty (because 
`Collections` will usually return unmodifiable maps). This way, if someone 
tries to add content to this map to a later release, he/she will receive an 
`UnsupportedOperationException` which will make them think about why this was 
unmodifiable in the first place.
   As this only kicks in if the original map `kvPairs` is empty, this seems a 
sane choice.
   
   Then, `Collections::emptyMap` might receive performance updates in future 
releases, while `HashMap::new` is less likely to.




----------------------------------------------------------------
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.

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


Reply via email to