Skip to content

Commit

Permalink
fix : fill cache of InMemoryGroupDaoHandler with a Modifiable Map - E…
Browse files Browse the repository at this point in the history
…XO-72017

Before this fix, when we call computeIfAbsent in
InMemoryGroupDaoHandler, and when the item is not in cache, then the
create map is done with Collections.emptyMap(). As this map is a non
modifiable map, it is not possible to create a group in a test after
that as it throws a UnsupportedExecption

This commit change the map to a classic empty Hashmap, so that it can be
updated in the future

Resolves Meeds-io/meeds#2068

<!-- Ensure to provide github issue and task id in the title -->
<!-- Choose between feat and fix in the title to differenciate a new
feature from a fix -->
<!-- Title format must be :
feat: FEATURE TITLE - MEED-XXXX - Meeds-io/meeds#1234
or
fix: Fix TITLE - MEED-XXXX - Meeds-io/meeds#1234
-->

<!-- Description : describe the feature/the fix by answering theses
questions : -->
<!-- Why is this change needed?-->
<!-- Prior to this change, ...-->
<!-- How does it address the issue?-->
<!-- This change ...-->


<!-- Tips : 
Try To Limit Each Line to a Maximum Of 72 Characters
Provide links or keys to any relevant tickets, articles or other
resources

Remember to
- Capitalize the subject line
- Use the imperative mood in the subject line
- Do not end the subject line with a period
- Separate subject from body with a blank line
- Use the body to explain what and why vs. how
- Can use multiple lines with "-" for bullet points in body
-->
  • Loading branch information
rdenarie authored and exo-swf committed Jun 3, 2024
1 parent 5c0db68 commit f4ff3ed
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public Group findGroupById(String groupId) {

@Override
public ListAccess<Group> findGroupChildren(Group parent, String keyword) {
List<Group> childGroups = groupChildsById.computeIfAbsent(parent.getId(), key -> Collections.emptyMap())
List<Group> childGroups = groupChildsById.computeIfAbsent(parent.getId(), key -> new HashMap<>())
.values()
.stream()
.filter(group -> StringUtils.contains(group.getLabel(), keyword)
Expand All @@ -185,7 +185,7 @@ public ListAccess<Group> findGroupChildren(Group parent, String keyword) {
}

public Collection<Group> findGroups(Group parent) {
return groupChildsById.computeIfAbsent(parent.getId(), key -> Collections.emptyMap())
return groupChildsById.computeIfAbsent(parent.getId(), key -> new HashMap<>())
.values()
.stream()
.map(ObjectUtils::clone)
Expand Down

0 comments on commit f4ff3ed

Please sign in to comment.