Sonar: Method params shouldn't be reassigned 63/31063/1
authorLorand Jakab <lojakab@cisco.com>
Wed, 9 Dec 2015 10:41:05 +0000 (12:41 +0200)
committerLorand Jakab <lojakab@cisco.com>
Wed, 9 Dec 2015 10:41:05 +0000 (12:41 +0200)
Fix 14 instances of Sonar issue "Method parameters, caught exceptions
and foreach variables should not be reassigned" labeled as Major. The
rule description says: "While it is technically correct to assign to
parameters from within method bodies, it is better to use temporary
variables to store intermediate results. This rule will typically detect
cases where a constructor parameter is assigned to itself instead of a
field of the same name, i.e. when this was forgotten. Allowing
parameters to be assigned to also reduces the code readability as
developers will not be able to know whether the original parameter or
some temporary variable is being accessed without going through the
whole method. Moreover, some developers might also expect assignments of
method parameters to be visible from callers, which is not the case and
can confuse them. All parameters should be treated as final."

Change-Id: I488d2c3fbaf28814f207f65027f80d4b7d0e622e
Signed-off-by: Lorand Jakab <lojakab@cisco.com>
mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/lisp/MapServer.java
mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/mapcache/MultiTableMapCache.java
mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/mapcache/SimpleMapCache.java
mappingservice/lisp-proto/src/main/java/org/opendaylight/lispflowmapping/lisp/serializer/address/AfiListSerializer.java
mappingservice/lisp-proto/src/main/java/org/opendaylight/lispflowmapping/lisp/serializer/address/ExplicitLocatorPathSerializer.java
mappingservice/lisp-proto/src/main/java/org/opendaylight/lispflowmapping/lisp/util/MaskUtil.java
mappingservice/southbound/src/main/java/org/opendaylight/lispflowmapping/southbound/LispSouthboundStats.java
mappingservice/southbound/src/main/java/org/opendaylight/lispflowmapping/southbound/util/LispNotificationHelper.java

index e5caa58aa1e2a54056d8e3a92a4a7e69965aa503..204fade5120be937f8956618af61bdd683506022 100644 (file)
@@ -146,12 +146,12 @@ public class MapServer implements IMapServerAsync, OdlMappingserviceListener {
         // For SrcDst LCAF also send SMRs to Dst prefix
         if (eid.getAddress() instanceof SourceDestKey) {
             Eid dstAddr = SourceDestKeyHelper.getDst(eid);
-            subscribers = getSubscribers(dstAddr);
+            Set<SubscriberRLOC> dstSubs = getSubscribers(dstAddr);
             MappingRecord newRecord = new MappingRecordBuilder().setAction(record.getAction())
                     .setAuthoritative(record.isAuthoritative()).setLocatorRecord(record.getLocatorRecord())
                     .setMapVersion(record.getMapVersion()).setRecordTtl(record.getRecordTtl())
                     .setEid(dstAddr).build();
-            handleSmr(newRecord, subscribers, notifyHandler);
+            handleSmr(newRecord, dstSubs, notifyHandler);
         }
     }
 
index d70e0670ab1fbcef50eba89d17a1b38a711c26d5..4f1b0caff47ce1a9ddf5c65bc9632350fe642121 100644 (file)
@@ -173,32 +173,32 @@ public class MultiTableMapCache implements IMapCache {
     }
 
     public void removeMapping(Eid eid, boolean overwrite) {
-        eid = MaskUtil.normalize(eid);
-        ILispDAO table = getVniTable(eid);
+        Eid key = MaskUtil.normalize(eid);
+        ILispDAO table = getVniTable(key);
         if (table == null) {
             return;
         }
 
-        if (eid.getAddress() instanceof SourceDestKey) {
-            ILispDAO db = getSDInnerDao(eid, table);
+        if (key.getAddress() instanceof SourceDestKey) {
+            ILispDAO db = getSDInnerDao(key, table);
             if (db != null) {
-                db.removeSpecific(SourceDestKeyHelper.getSrc(eid),
+                db.removeSpecific(SourceDestKeyHelper.getSrc(key),
                         SubKeys.RECORD);
             }
         } else {
-            table.removeSpecific(eid, SubKeys.RECORD);
+            table.removeSpecific(key, SubKeys.RECORD);
         }
     }
 
-    public void addAuthenticationKey(Eid eid, MappingAuthkey key) {
-        eid = MaskUtil.normalize(eid);
-        ILispDAO table = getOrInstantiateVniTable(eid);
+    public void addAuthenticationKey(Eid eid, MappingAuthkey authKey) {
+        Eid key = MaskUtil.normalize(eid);
+        ILispDAO table = getOrInstantiateVniTable(key);
 
-        if (eid.getAddress() instanceof SourceDestKey) {
-            ILispDAO srcDstDao = getOrInstantiateSDInnerDao(eid, table);
-            srcDstDao.put(SourceDestKeyHelper.getSrc(eid), new MappingEntry<>(SubKeys.AUTH_KEY, key));
+        if (key.getAddress() instanceof SourceDestKey) {
+            ILispDAO srcDstDao = getOrInstantiateSDInnerDao(key, table);
+            srcDstDao.put(SourceDestKeyHelper.getSrc(key), new MappingEntry<>(SubKeys.AUTH_KEY, authKey));
         } else {
-            table.put(eid, new MappingEntry<>(SubKeys.AUTH_KEY, key));
+            table.put(key, new MappingEntry<>(SubKeys.AUTH_KEY, authKey));
         }
     }
 
@@ -242,19 +242,19 @@ public class MultiTableMapCache implements IMapCache {
     }
 
     public void removeAuthenticationKey(Eid eid) {
-        eid = MaskUtil.normalize(eid);
-        ILispDAO table = getVniTable(eid);
+        Eid key = MaskUtil.normalize(eid);
+        ILispDAO table = getVniTable(key);
         if (table == null) {
             return;
         }
 
-        if (eid.getAddress() instanceof SourceDestKey) {
-            ILispDAO srcDstDao = getSDInnerDao(eid, table);
+        if (key.getAddress() instanceof SourceDestKey) {
+            ILispDAO srcDstDao = getSDInnerDao(key, table);
             if (srcDstDao != null) {
-                srcDstDao.removeSpecific(eid, SubKeys.AUTH_KEY);
+                srcDstDao.removeSpecific(key, SubKeys.AUTH_KEY);
             }
         } else {
-            table.removeSpecific(eid, SubKeys.AUTH_KEY);
+            table.removeSpecific(key, SubKeys.AUTH_KEY);
         }
     }
 
@@ -337,8 +337,8 @@ public class MultiTableMapCache implements IMapCache {
     }
 
     @Override
-    public void addData(Eid key, String subKey, Object data) {
-        key = MaskUtil.normalize(key);
+    public void addData(Eid eid, String subKey, Object data) {
+        Eid key = MaskUtil.normalize(eid);
         ILispDAO table = getOrInstantiateVniTable(key);
 
 
@@ -366,8 +366,8 @@ public class MultiTableMapCache implements IMapCache {
     }
 
     @Override
-    public void removeData(Eid key, String subKey) {
-        key = MaskUtil.normalize(key);
+    public void removeData(Eid eid, String subKey) {
+        Eid key = MaskUtil.normalize(eid);
         ILispDAO table = getVniTable(key);
         if (table == null) {
             return;
index b1492bc5f7bee61ace303c58d18ab624bd887116..8e87510a701367ec3878563a8b3ce98aabaaf7a1 100644 (file)
@@ -151,19 +151,19 @@ public class SimpleMapCache implements IMapCache {
     }
 
     public void removeMapping(Eid eid, boolean overwrite) {
-        eid = MaskUtil.normalize(eid);
-        ILispDAO table = getVniTable(eid);
+        Eid key = MaskUtil.normalize(eid);
+        ILispDAO table = getVniTable(key);
         if (table == null) {
             return;
         }
 
-        table.removeSpecific(eid, SubKeys.RECORD);
+        table.removeSpecific(key, SubKeys.RECORD);
     }
 
-    public void addAuthenticationKey(Eid eid, MappingAuthkey key) {
-        eid = MaskUtil.normalize(eid);
-        ILispDAO table = getOrInstantiateVniTable(eid);
-        table.put(eid, new MappingEntry<>(SubKeys.AUTH_KEY, key));
+    public void addAuthenticationKey(Eid eid, MappingAuthkey authKey) {
+        Eid key = MaskUtil.normalize(eid);
+        ILispDAO table = getOrInstantiateVniTable(key);
+        table.put(key, new MappingEntry<>(SubKeys.AUTH_KEY, authKey));
     }
 
     private MappingAuthkey getAuthKeyLpm(Eid prefix, ILispDAO db) {
@@ -198,12 +198,12 @@ public class SimpleMapCache implements IMapCache {
     }
 
     public void removeAuthenticationKey(Eid eid) {
-        eid = MaskUtil.normalize(eid);
-        ILispDAO table = getVniTable(eid);
+        Eid key = MaskUtil.normalize(eid);
+        ILispDAO table = getVniTable(key);
         if (table == null) {
             return;
         }
-        table.removeSpecific(eid, SubKeys.AUTH_KEY);
+        table.removeSpecific(key, SubKeys.AUTH_KEY);
     }
 
     public String printMappings() {
index cc00a3dd1bed915d4c51f864a42853182d2e6618..51bdf06371bea93919e41467c66fda7d5414c1d3 100644 (file)
@@ -84,8 +84,9 @@ public final class AfiListSerializer extends LcafSerializer {
         return rb.build();
     }
 
-    private Address deserializeData(ByteBuffer buffer, short length, LispAddressSerializerContext ctx) {
+    private Address deserializeData(ByteBuffer buffer, short lcafLength, LispAddressSerializerContext ctx) {
         List<SimpleAddress> addresses = new ArrayList<SimpleAddress>();
+        short length = lcafLength;
         while (length > 0) {
             SimpleAddress address = SimpleAddressSerializer.getInstance().deserialize(buffer, ctx);
             length -= SimpleAddressSerializer.getInstance().getAddressSize(address);
index 573357de7e9c9ce9eb96daa597cf8cf423a5d039..0daeb6c72206068c766e14b1539bd4ee957e71ac 100644 (file)
@@ -99,8 +99,9 @@ public final class ExplicitLocatorPathSerializer extends LcafSerializer {
         return rb.build();
     }
 
-    private Address deserializeData(ByteBuffer buffer, short length, LispAddressSerializerContext ctx) {
+    private Address deserializeData(ByteBuffer buffer, short lcafLength, LispAddressSerializerContext ctx) {
         List<Hop> hops = new ArrayList<Hop>();
+        short length = lcafLength;
         while (length > 0) {
             byte flags = (byte) buffer.getShort();
             boolean lookup = ByteUtil.extractBit(flags, Flags.LOOKUP);
index 1162ffa305c6c649bb39f6bd88e21376e3c3043c..b1abf48cd429733feb0b01c9ae3317fd20621bef 100644 (file)
@@ -96,9 +96,10 @@ public final class MaskUtil {
         return eid;
     }
 
-    private static InetAddress normalizeIP(InetAddress address, int mask) throws UnknownHostException {
+    private static InetAddress normalizeIP(InetAddress address, int maskLength) throws UnknownHostException {
         ByteBuffer byteRepresentation = ByteBuffer.wrap(address.getAddress());
         byte b = (byte) 0xff;
+        int mask = maskLength;
         for (int i = 0; i < byteRepresentation.array().length; i++) {
             if (mask >= 8) {
                 byteRepresentation.put(i, (byte) (b & byteRepresentation.get(i)));
index 7f4281d880859e835271bb48b21602cea8ce0ab2..3ab543da9e65629e97f0886bf50271ed78bce176 100644 (file)
@@ -70,7 +70,7 @@ public class LispSouthboundStats {
         if (value == Long.MAX_VALUE) {
             return 0;
         } else {
-            return ++value;
+            return value + 1;
         }
     }
 
index 54438e46fad1edc847b0ab448fe59d4929329875..51aa82e9d5cfdbc7bb4f4612a1a47af7da50d58b 100644 (file)
@@ -61,7 +61,8 @@ public final class LispNotificationHelper {
                 .setProbe(mapReply.isProbe()).setSecurityEnabled(mapReply.isSecurityEnabled()).build();
     }
 
-    public static IpAddress getIpAddressFromInetAddress(InetAddress inetAddress) {
+    public static IpAddress getIpAddressFromInetAddress(InetAddress address) {
+        InetAddress inetAddress = address;
         if (inetAddress == null) {
             inetAddress = InetAddress.getLoopbackAddress();
         }