Copilot commented on code in PR #11048:
URL: https://github.com/apache/cloudstack/pull/11048#discussion_r3939020645
##########
framework/spring/module/src/main/java/org/apache/cloudstack/spring/module/model/impl/DefaultModuleDefinitionSet.java:
##########
@@ -310,24 +314,36 @@ public Map<String, ApplicationContext> getContextMap() {
@Override
public Resource[] getConfigResources(String name) {
- Set<Resource> resources = new LinkedHashSet<Resource>();
-
- ModuleDefinition original = null;
- ModuleDefinition def = original = modules.get(name);
-
- if (def == null)
+ ModuleDefinition def = modules.get(name);
+ if (def == null) {
return new Resource[] {};
+ }
+
+ Set<Resource> resources = new LinkedHashSet<>();
resources.addAll(def.getContextLocations());
- while (def != null) {
- resources.addAll(def.getInheritableContextLocations());
- def = modules.get(def.getParentName());
+ resources.addAll(collectInheritedResources(def));
+
+ resources.addAll(def.getOverrideContextLocations());
+
+ return resources.toArray(Resource[]::new);
+ }
+
+ private Set<Resource> collectInheritedResources(final ModuleDefinition
def) {
+ if (def == null) {
+ return Collections.emptySet();
}
- resources.addAll(original.getOverrideContextLocations());
+ final Set<Resource> cachedResources =
inheritedConfigResourcesMap.get(def.getName());
+ if (cachedResources != null) {
+ return cachedResources;
+ }
Review Comment:
`collectInheritedResources` memoizes into a plain `HashMap` from a public
method without any synchronization. If `getConfigResources()` is called
concurrently (e.g., by multiple threads building/inspecting contexts), the
unsynchronized `get`/`put` can corrupt the map or produce inconsistent results.
Consider synchronizing access (or switching to a concurrent map) and caching an
immutable set to avoid accidental mutation of cached values.
--
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]