Sonar: if/else/for/while/do statements need braces 09/30909/2
authorLorand Jakab <lojakab@cisco.com>
Mon, 7 Dec 2015 18:58:58 +0000 (20:58 +0200)
committerLorand Jakab <lojakab@cisco.com>
Mon, 7 Dec 2015 18:58:58 +0000 (20:58 +0200)
Fix 23 instances of Sonar issue "if/else/for/while/do statements should
always use curly braces" labeled as "Major".

Add checkstyle rule to avoid introducing more of these.

Change-Id: I17152d437349c9ca45018421f6e580130c51c4e6
Signed-off-by: Lorand Jakab <lojakab@cisco.com>
commons/build_tools/src/main/resources/checkstyle/java_rules.xml
mappingservice/api/src/main/java/org/opendaylight/lispflowmapping/interfaces/dao/MappingEntry.java
mappingservice/api/src/main/java/org/opendaylight/lispflowmapping/interfaces/dao/MappingValueKey.java
mappingservice/api/src/main/java/org/opendaylight/lispflowmapping/interfaces/dao/SubscriberRLOC.java
mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/config/ConfigIni.java
mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/lisp/MapServer.java
mappingservice/lisp-proto/src/main/java/org/opendaylight/lispflowmapping/lisp/serializer/address/MacSerializer.java
mappingservice/lisp-proto/src/main/java/org/opendaylight/lispflowmapping/lisp/util/MaskUtil.java

index 13216416b9f9d748ca70135515ee70ab572ee5ce..b4b6efcc9292146c8f6da7a632627d1942040d12 100644 (file)
@@ -27,6 +27,7 @@
        <module name="RedundantImport"/>
        <module name="UnusedImports"/>
        <module name="AvoidStarImport"/>
+       <module name="NeedBraces"/>
        <module name="UpperEll"/>
        <module name="EmptyStatement"/>
        <module name="EqualsHashCode"/>
index 9761579eb50eb1e7baa620ca8f65d03e34f970c2..c1cf1d55103487f6a7764fcf126c28c289c3d0fe 100644 (file)
@@ -41,23 +41,30 @@ public class MappingEntry<V> {
 
     @Override
     public boolean equals(Object obj) {
-        if (this == obj)
+        if (this == obj) {
             return true;
-        if (obj == null)
+        }
+        if (obj == null) {
             return false;
-        if (getClass() != obj.getClass())
+        }
+        if (getClass() != obj.getClass()) {
             return false;
+        }
         MappingEntry other = (MappingEntry) obj;
         if (mappingValueKey == null) {
-            if (other.mappingValueKey != null)
+            if (other.mappingValueKey != null) {
                 return false;
-        } else if (!mappingValueKey.equals(other.mappingValueKey))
+            }
+        } else if (!mappingValueKey.equals(other.mappingValueKey)) {
             return false;
+        }
         if (value == null) {
-            if (other.value != null)
+            if (other.value != null) {
                 return false;
-        } else if (!value.equals(other.value))
+            }
+        } else if (!value.equals(other.value)) {
             return false;
+        }
         return true;
     }
 
index 25231e357bbf28d010309b92acc54d2344da1665..5d5c58d8232a5c56eb16bb42e47893aa2d9fb4b2 100644 (file)
@@ -35,18 +35,23 @@ public class MappingValueKey<V> {
 
     @Override
     public boolean equals(Object obj) {
-        if (this == obj)
+        if (this == obj) {
             return true;
-        if (obj == null)
+        }
+        if (obj == null) {
             return false;
-        if (getClass() != obj.getClass())
+        }
+        if (getClass() != obj.getClass()) {
             return false;
+        }
         MappingValueKey<?> other = (MappingValueKey<?>) obj;
         if (key == null) {
-            if (other.key != null)
+            if (other.key != null) {
                 return false;
-        } else if (!key.equals(other.key))
+            }
+        } else if (!key.equals(other.key)) {
             return false;
+        }
         return true;
     }
 }
index 052655a9f2660994561fc29dd5290a140674df99..95791961d5cc6709233a373ce57c653c3325ddb9 100644 (file)
@@ -72,15 +72,19 @@ public class SubscriberRLOC {
 
     @Override
     public boolean equals(Object obj) {
-        if (this == obj)
+        if (this == obj) {
             return true;
-        if (obj == null)
+        }
+        if (obj == null) {
             return false;
-        if (getClass() != obj.getClass())
+        }
+        if (getClass() != obj.getClass()) {
             return false;
+        }
         SubscriberRLOC other = (SubscriberRLOC) obj;
-        if (!rloc.equals(other.rloc))
+        if (!rloc.equals(other.rloc)) {
             return false;
+        }
         return true;
     }
 
index dac82578a467377c846f9d3b15f3e527d810396b..d770d076fa128311b9e826551e318f8aa2263c42 100644 (file)
@@ -41,8 +41,9 @@ public class ConfigIni {
 
         String str = null;
 
-        if (context != null)
+        if (context != null) {
             str = context.getProperty(LISP_MAPPING_OVERWRITE);
+        }
 
         if (str == null) {
             str = System.getProperty(LISP_MAPPING_OVERWRITE);
@@ -66,8 +67,9 @@ public class ConfigIni {
 
         String str = null;
 
-        if (context != null)
+        if (context != null) {
             str = context.getProperty(LISP_SMR);
+        }
 
         if (str == null) {
             str = System.getProperty(LISP_SMR);
@@ -91,8 +93,9 @@ public class ConfigIni {
 
         String str = null;
 
-        if (context != null)
+        if (context != null) {
             str = context.getProperty(LISP_ELP_POLICY);
+        }
 
         if (str == null) {
             str = System.getProperty(LISP_ELP_POLICY);
index 06a16fa236fa39cee6fb8f1c15a7997c16ae7c64..e5caa58aa1e2a54056d8e3a92a4a7e69965aa503 100644 (file)
@@ -199,14 +199,16 @@ public class MapServer implements IMapServerAsync, OdlMappingserviceListener {
             while (interfaces.hasMoreElements()) {
                 NetworkInterface current = interfaces.nextElement();
                 LOG.debug("Interface " + current.toString());
-                if (!current.isUp() || current.isLoopback() || current.isVirtual())
+                if (!current.isUp() || current.isLoopback() || current.isVirtual()) {
                     continue;
+                }
                 Enumeration<InetAddress> addresses = current.getInetAddresses();
                 while (addresses.hasMoreElements()) {
                     InetAddress current_addr = addresses.nextElement();
                     // Skip loopback and link local addresses
-                    if (current_addr.isLoopbackAddress() || current_addr.isLinkLocalAddress())
+                    if (current_addr.isLoopbackAddress() || current_addr.isLinkLocalAddress()) {
                         continue;
+                    }
                     LOG.debug(current_addr.getHostAddress());
                     return current_addr;
                 }
index 70f7b0644cd5b390ddd4017701f7ce5249e1713b..d2358a0cdff7024e7bce7331516db2329fbfba89 100644 (file)
@@ -93,8 +93,9 @@ public class MacSerializer extends LispAddressSerializer {
         buffer.get(macBuffer);
         StringBuilder sb = new StringBuilder(17);
         for (byte b : macBuffer) {
-            if (sb.length() > 0)
+            if (sb.length() > 0) {
                 sb.append(':');
+            }
             sb.append(String.format("%02x", b));
         }
         return new MacAddress(sb.toString());
index 802a79f90eea0da6ecb3efcab5fc64d9d340355a..3b61db8522caac0613b9a114ec49621921a8a953 100644 (file)
@@ -96,10 +96,9 @@ public class MaskUtil {
         ByteBuffer byteRepresentation = ByteBuffer.wrap(address.getAddress());
         byte b = (byte) 0xff;
         for (int i = 0; i < byteRepresentation.array().length; i++) {
-            if (mask >= 8)
+            if (mask >= 8) {
                 byteRepresentation.put(i, (byte) (b & byteRepresentation.get(i)));
-
-            else if (mask > 0) {
+            } else if (mask > 0) {
                 byteRepresentation.put(i, (byte) ((byte) (b << (8 - mask)) & byteRepresentation.get(i)));
             } else {
                 byteRepresentation.put(i, (byte) (0 & byteRepresentation.get(i)));