james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [16/24] james-project git commit: JAMES-2366 HBase RRT implementation should not rely on null
Date Fri, 20 Apr 2018 02:13:01 GMT
JAMES-2366 HBase RRT implementation should not rely on null


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/d4a80ca1
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/d4a80ca1
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/d4a80ca1

Branch: refs/heads/master
Commit: d4a80ca14055f3ecc15c6e2dee1f9a9a71a26139
Parents: e0dbdbd
Author: benwa <btellier@linagora.com>
Authored: Mon Apr 9 12:58:57 2018 +0700
Committer: benwa <btellier@linagora.com>
Committed: Fri Apr 20 09:12:01 2018 +0700

----------------------------------------------------------------------
 .../rrt/hbase/HBaseRecipientRewriteTable.java   | 21 +++++++-------------
 1 file changed, 7 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/d4a80ca1/server/data/data-hbase/src/main/java/org/apache/james/rrt/hbase/HBaseRecipientRewriteTable.java
----------------------------------------------------------------------
diff --git a/server/data/data-hbase/src/main/java/org/apache/james/rrt/hbase/HBaseRecipientRewriteTable.java
b/server/data/data-hbase/src/main/java/org/apache/james/rrt/hbase/HBaseRecipientRewriteTable.java
index cd5ca2a..d2556c3 100644
--- a/server/data/data-hbase/src/main/java/org/apache/james/rrt/hbase/HBaseRecipientRewriteTable.java
+++ b/server/data/data-hbase/src/main/java/org/apache/james/rrt/hbase/HBaseRecipientRewriteTable.java
@@ -51,9 +51,6 @@ import com.google.common.base.Splitter;
  */
 public class HBaseRecipientRewriteTable extends AbstractRecipientRewriteTable {
 
-    /**
-     * The Logger.
-     */
     private static final Logger log = LoggerFactory.getLogger(HBaseRecipientRewriteTable.class.getName());
     private static final String ROW_SEPARATOR = "@";
     private static final String COLUMN_SEPARATOR = ";";
@@ -63,7 +60,7 @@ public class HBaseRecipientRewriteTable extends AbstractRecipientRewriteTable
{
         String fixedUser = getFixedUser(user);
         Domain fixedDomain = getFixedDomain(domain);
         Mappings map = getUserDomainMappings(fixedUser, fixedDomain);
-        if (map != null && map.size() != 0) {
+        if (!map.isEmpty()) {
             Mappings updatedMappings = MappingsImpl.from(map).add(mapping).build();
             doUpdateMapping(fixedUser, fixedDomain, updatedMappings.serialize());
         } else {
@@ -111,7 +108,7 @@ public class HBaseRecipientRewriteTable extends AbstractRecipientRewriteTable
{
     protected Map<String, Mappings> getAllMappingsInternal() throws RecipientRewriteTableException
{
         HTableInterface table = null;
         ResultScanner resultScanner = null;
-        Map<String, Mappings> map = null;
+        Map<String, Mappings> map = new HashMap<>();
         try {
             table = TablePool.getInstance().getRecipientRewriteTable();
             Scan scan = new Scan();
@@ -124,9 +121,6 @@ public class HBaseRecipientRewriteTable extends AbstractRecipientRewriteTable
{
                 if (keyValues != null) {
                     for (KeyValue keyValue : keyValues) {
                         String email = Bytes.toString(keyValue.getRow());
-                        if (map == null) {
-                            map = new HashMap<>();
-                        }
                         Mappings mappings = 
                                 MappingsImpl.from(
                                     Optional.ofNullable(
@@ -159,7 +153,7 @@ public class HBaseRecipientRewriteTable extends AbstractRecipientRewriteTable
{
     @Override
     protected Mappings mapAddress(String user, Domain domain) throws RecipientRewriteTableException
{
         HTableInterface table = null;
-        String mappings = null;
+        String mappings;
         try {
             table = TablePool.getInstance().getRecipientRewriteTable();
             mappings = getMapping(table, user, domain);
@@ -181,7 +175,7 @@ public class HBaseRecipientRewriteTable extends AbstractRecipientRewriteTable
{
                 }
             }
         }
-        return MappingsImpl.fromRawString(mappings);
+        return MappingsImpl.fromRawString(Optional.ofNullable(mappings).orElse(""));
     }
 
     private String getMapping(HTableInterface table, String user, Domain domain) throws IOException
{
@@ -201,11 +195,11 @@ public class HBaseRecipientRewriteTable extends AbstractRecipientRewriteTable
{
         String fixedUser = getFixedUser(user);
         Domain fixedDomain = getFixedDomain(domain);
         Mappings map = getUserDomainMappings(fixedUser, fixedDomain);
-        if (map != null && map.size() > 1) {
+        if (map.size() > 1) {
             Mappings updatedMappings = map.remove(mapping);
             doUpdateMapping(fixedUser, fixedDomain, updatedMappings.serialize());
         } else {
-            doRemoveMapping(fixedUser, fixedDomain, mapping.asString());
+            doRemoveMapping(fixedUser, fixedDomain);
         }
     }
 
@@ -228,10 +222,9 @@ public class HBaseRecipientRewriteTable extends AbstractRecipientRewriteTable
{
      * 
      * @param user the user
      * @param domain the domain
-     * @param mapping the mapping
      * @throws RecipientRewriteTableException
      */
-    private void doRemoveMapping(String user, Domain domain, String mapping) throws RecipientRewriteTableException
{
+    private void doRemoveMapping(String user, Domain domain) throws RecipientRewriteTableException
{
         HTableInterface table = null;
         try {
             table = TablePool.getInstance().getRecipientRewriteTable();


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message