This is an automated email from the ASF dual-hosted git repository.

rcordier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 8a7f3fbfda5d0d48053d3fd6ab3057adb3483c7d
Author: Quan Tran <hqt...@linagora.com>
AuthorDate: Tue Nov 12 11:23:05 2024 +0700

    JAMES-4087 Use Optional to handle null
---
 .../mailetcontainer/lib/AbstractStateMailetProcessor.java | 15 +++++----------
 1 file changed, 5 insertions(+), 10 deletions(-)

diff --git 
a/server/mailet/mailetcontainer-impl/src/main/java/org/apache/james/mailetcontainer/lib/AbstractStateMailetProcessor.java
 
b/server/mailet/mailetcontainer-impl/src/main/java/org/apache/james/mailetcontainer/lib/AbstractStateMailetProcessor.java
index 5455bbf903..c031b5e4ea 100644
--- 
a/server/mailet/mailetcontainer-impl/src/main/java/org/apache/james/mailetcontainer/lib/AbstractStateMailetProcessor.java
+++ 
b/server/mailet/mailetcontainer-impl/src/main/java/org/apache/james/mailetcontainer/lib/AbstractStateMailetProcessor.java
@@ -23,6 +23,7 @@ import java.util.Collection;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Optional;
 import java.util.concurrent.ConcurrentLinkedDeque;
 
 import jakarta.annotation.PostConstruct;
@@ -54,6 +55,7 @@ import org.apache.mailet.base.MatcherInverter;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.github.fge.lambdas.Throwing;
 import com.google.common.collect.ImmutableList;
 
 /**
@@ -336,16 +338,9 @@ public abstract class AbstractStateMailetProcessor 
implements MailProcessor, Con
         }
     }
 
-    private Matcher loadMatcher(Map<String, Matcher> compositeMatchers, String 
matcherName) throws MessagingException {
-        Matcher matcher;
-        // try to load from compositeMatchers first
-        matcher = compositeMatchers.get(matcherName);
-        if (matcher == null) {
-            // no composite Matcher found, try to load it via
-            // MatcherLoader
-            matcher = 
matcherLoader.getMatcher(createMatcherConfig(matcherName));
-        }
-        return matcher;
+    private Matcher loadMatcher(Map<String, Matcher> compositeMatchers, String 
matcherName) {
+        return Optional.ofNullable(compositeMatchers.get(matcherName))
+            .orElseGet(Throwing.supplier(() -> 
matcherLoader.getMatcher(createMatcherConfig(matcherName))));
     }
 
     /**


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

Reply via email to