chibenwa commented on code in PR #2644:
URL: https://github.com/apache/james-project/pull/2644#discussion_r1961169842


##########
mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/mail/InMemoryMailboxMapper.java:
##########
@@ -134,12 +135,15 @@ public Flux<Mailbox> list() {
 
     @Override
     public Mono<ACLDiff> updateACL(Mailbox mailbox, MailboxACL.ACLCommand 
mailboxACLCommand) {
-        return Mono.fromCallable(() -> {
-            MailboxACL oldACL = mailbox.getACL();
-            MailboxACL newACL = mailbox.getACL().apply(mailboxACLCommand);
-            
mailboxesByPath.get(mailbox.generateAssociatedPath()).setACL(newACL);
-            return ACLDiff.computeDiff(oldACL, newACL);
-        });
+        return Mono.just(mailbox.getACL())
+            .flatMap(oldACL -> Mono.fromCallable(() -> 
mailboxesByPath.compute(mailbox.generateAssociatedPath(), (path, 
existingMailbox) -> {
+                    if (existingMailbox == null) {
+                        throw new IllegalArgumentException("Mailbox not found 
for path: " + path);
+                    }
+                    Throwing.runnable(() -> 
existingMailbox.setACL(existingMailbox.getACL().apply(mailboxACLCommand))).run();

Review Comment:
   I prefer a try-catch block rather than this half functional code.



##########
mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/mail/InMemoryMailboxMapper.java:
##########
@@ -134,12 +135,15 @@ public Flux<Mailbox> list() {
 
     @Override
     public Mono<ACLDiff> updateACL(Mailbox mailbox, MailboxACL.ACLCommand 
mailboxACLCommand) {
-        return Mono.fromCallable(() -> {
-            MailboxACL oldACL = mailbox.getACL();
-            MailboxACL newACL = mailbox.getACL().apply(mailboxACLCommand);
-            
mailboxesByPath.get(mailbox.generateAssociatedPath()).setACL(newACL);
-            return ACLDiff.computeDiff(oldACL, newACL);
-        });
+        return Mono.just(mailbox.getACL())
+            .flatMap(oldACL -> Mono.fromCallable(() -> 
mailboxesByPath.compute(mailbox.generateAssociatedPath(), (path, 
existingMailbox) -> {

Review Comment:
   The fact that mailboxes are indexed by path, which is mutable, creates 
unecessary complexity.
   
   I'm then also 100% sure that there's a data race between ACL update and 
mailbox renames that WILL bite back when implementing right propagation upon 
renames of team mailboxes.
   
   I would seriously advise using `mailboxesById` which would be a 
Map<MailboxId, Mailbox> instead...
   
   



-- 
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: notifications-unsubscr...@james.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscr...@james.apache.org
For additional commands, e-mail: notifications-h...@james.apache.org

Reply via email to