Fix findbugs/sonar violations in sfc-scf-openflow 05/63305/3
authorTom Pantelis <[email protected]>
Tue, 19 Sep 2017 02:51:27 +0000 (22:51 -0400)
committerTom Pantelis <[email protected]>
Wed, 20 Sep 2017 11:43:31 +0000 (07:43 -0400)
- Utility classes should not have public constructors
- Remove unnecessary throws declaration in close()
- Boxing/unboxing to parse a primitive
- Dead store to local variable

Also enabled findbugs enforcement.

Change-Id: I49b6f5de493a5625c02b322d7341ec2ae3688d73
Signed-off-by: Tom Pantelis <[email protected]>
sfc-classifiers/sfc-scf-openflow/pom.xml
sfc-classifiers/sfc-scf-openflow/src/main/java/org/opendaylight/sfc/scfofrenderer/flowgenerators/MacChainingClassifier.java
sfc-classifiers/sfc-scf-openflow/src/main/java/org/opendaylight/sfc/scfofrenderer/listeners/ClassifierRspsUpdateListener.java
sfc-classifiers/sfc-scf-openflow/src/main/java/org/opendaylight/sfc/scfofrenderer/listeners/SfcScfOfDataListener.java
sfc-classifiers/sfc-scf-openflow/src/main/java/org/opendaylight/sfc/scfofrenderer/processors/OpenflowClassifierProcessor.java
sfc-classifiers/sfc-scf-openflow/src/main/java/org/opendaylight/sfc/scfofrenderer/renderers/SfcScfOfRenderer.java
sfc-classifiers/sfc-scf-openflow/src/main/java/org/opendaylight/sfc/scfofrenderer/utils/SfcScfMatch.java
sfc-classifiers/sfc-scf-openflow/src/main/java/org/opendaylight/sfc/scfofrenderer/utils/SfcScfOfUtils.java

index e3e7839eb249aec9f855c8b9e7d2280250f85117..af303d859ac0c508dd921bd0649cf78aee89bd2f 100644 (file)
           <propertyExpansion>checkstyle.violationSeverity=error</propertyExpansion>
         </configuration>
       </plugin>
+      <plugin>
+        <groupId>org.codehaus.mojo</groupId>
+        <artifactId>findbugs-maven-plugin</artifactId>
+        <configuration>
+          <failOnError>true</failOnError>
+        </configuration>
+      </plugin>
       <plugin>
         <groupId>org.codehaus.mojo</groupId>
         <artifactId>build-helper-maven-plugin</artifactId>
index a37b3172355b06cf9ad803bc85ad6c3f6eeb2f2b..8f44ddb4ec5d15702fceb082e598bfb55f3bc431 100644 (file)
@@ -9,10 +9,8 @@
 package org.opendaylight.sfc.scfofrenderer.flowgenerators;
 
 import com.google.common.collect.Iterables;
-
 import java.util.List;
 import java.util.Optional;
-
 import org.opendaylight.sfc.ovs.provider.SfcOvsUtil;
 import org.opendaylight.sfc.provider.api.SfcProviderRenderedPathAPI;
 import org.opendaylight.sfc.provider.api.SfcProviderServiceForwarderAPI;
@@ -37,7 +35,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.M
 
 
 public class MacChainingClassifier {
-    private ServiceFunctionForwarder sff;
+    private ServiceFunctionForwarder serviceFunctionForwarder;
 
     private final ClassifierHandler classifierHandler;
 
@@ -47,11 +45,11 @@ public class MacChainingClassifier {
 
     public MacChainingClassifier(ServiceFunctionForwarder theSff) {
         this();
-        sff = theSff;
+        serviceFunctionForwarder = theSff;
     }
 
     public MacChainingClassifier setSff(ServiceFunctionForwarder theSff) {
-        sff = theSff;
+        serviceFunctionForwarder = theSff;
         return this;
     }
 
@@ -167,7 +165,7 @@ public class MacChainingClassifier {
 
 
     public Optional<String> getNodeName(String theInterfaceName) {
-        return Optional.ofNullable(sff)
+        return Optional.ofNullable(serviceFunctionForwarder)
                 .filter(theSff -> theSff.getAugmentation(SffOvsBridgeAugmentation.class) != null)
                 .map(SfcOvsUtil::getOpenFlowNodeIdForSff);
     }
index 2e38fe1727aa642946402f739ed30cf6dd8a01d1..01dc4536dea0496e7217cf46d0e2412107f5f72f 100644 (file)
@@ -105,7 +105,7 @@ public class ClassifierRspsUpdateListener extends AbstractDataTreeChangeListener
     }
 
     @Override
-    public void close() throws Exception {
+    public void close() {
         listenerRegistration.close();
     }
 }
index 24e1f395205e300779436b72ead1d0a5bf1a6714..e2f1f95bfde527e6759d0d06fdb9d5366785b905 100644 (file)
@@ -86,7 +86,7 @@ public class SfcScfOfDataListener extends AbstractDataTreeChangeListener<Service
     }
 
     @Override
-    public void close() throws Exception {
+    public void close() {
         LOG.debug("Closing listener...");
         if (listenerRegistration != null) {
             listenerRegistration.close();
index 0a2c40a9ff1831365db4a326ea42ec6721423e28..9658f00bda7cf4a0f25379ff68c9f2b183ba3772 100644 (file)
@@ -177,7 +177,7 @@ public class OpenflowClassifierProcessor {
 
         ClassifierProcessorInterface classifierProcessor;
 
-        Optional<String> nodeName = Optional.empty();
+        final Optional<String> nodeName;
         if (rsp.getSfcEncapsulation() == MacChaining.class) {
             nodeName = Optional.of(theSff.getServiceNode().getValue());
             classifierProcessor = new MacChainingProcessor(
index ce5bc914c005c32809b9fb696c63ddcbc8770539..45a0be63fcd9a2b88fda596e3a08a735ecf75fb1 100644 (file)
@@ -8,7 +8,6 @@
 
 package org.opendaylight.sfc.scfofrenderer.renderers;
 
-import java.util.concurrent.ExecutionException;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
 import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
@@ -76,14 +75,9 @@ public class SfcScfOfRenderer implements AutoCloseable {
      * Implemented from the AutoCloseable interface.
      */
     @Override
-    @SuppressWarnings("checkstyle:IllegalCatch")
-    public void close() throws ExecutionException, InterruptedException {
+    public void close()  {
         LOG.info("SfcScfOfRenderer auto-closed");
-        try {
-            sfcScfDataListener.close();
-            classifierRspsUpdateListener.close();
-        } catch (Exception e) {
-            LOG.error("SfcScfOfRenderer auto-closed exception {}", e.getMessage());
-        }
+        sfcScfDataListener.close();
+        classifierRspsUpdateListener.close();
     }
 }
index ffa90c8b08471b0e005bd9a5d5c1c349a34ba865..f7bb311d0aa614beb71e3b74dd1a4f55d394be75 100644 (file)
@@ -132,13 +132,13 @@ public class SfcScfMatch {
                 Ipv4Prefix src = ipv4.getSourceIpv4Network();
                 if (src != null) {
                     String[] source = src.getValue().split("/");
-                    SfcOpenflowUtils.addMatchSrcIpv4(mb, source[0], Integer.valueOf(source[1]));
+                    SfcOpenflowUtils.addMatchSrcIpv4(mb, source[0], Integer.parseInt(source[1]));
                 }
 
                 Ipv4Prefix dst = ipv4.getDestinationIpv4Network();
                 if (dst != null) {
                     String[] destination = dst.getValue().split("/");
-                    SfcOpenflowUtils.addMatchDstIpv4(mb, destination[0], Integer.valueOf(destination[1]));
+                    SfcOpenflowUtils.addMatchDstIpv4(mb, destination[0], Integer.parseInt(destination[1]));
                 }
             }
             if (aceip.getAceIpVersion() instanceof AceIpv6) {
@@ -148,13 +148,13 @@ public class SfcScfMatch {
                 Ipv6Prefix src = ipv6.getSourceIpv6Network();
                 if (src != null) {
                     String[] source = src.getValue().split("/");
-                    SfcOpenflowUtils.addMatchSrcIpv6(mb, source[0], Integer.valueOf(source[1]));
+                    SfcOpenflowUtils.addMatchSrcIpv6(mb, source[0], Integer.parseInt(source[1]));
                 }
 
                 Ipv6Prefix dst = ipv6.getDestinationIpv6Network();
                 if (dst != null) {
                     String[] destination = dst.getValue().split("/");
-                    SfcOpenflowUtils.addMatchDstIpv6(mb, destination[0], Integer.valueOf(destination[1]));
+                    SfcOpenflowUtils.addMatchDstIpv6(mb, destination[0], Integer.parseInt(destination[1]));
                 }
             }
         }
index ae62dfe62c066c169c7f9981dee2b26ddf23f2f9..d4ea0b3aee03f4a6520df145e99b9d39c1190163 100644 (file)
@@ -36,6 +36,9 @@ public class SfcScfOfUtils {
     public static final short NSH_MDTYPE_ONE = 0x1;
     public static final short NSH_NP_ETH = 0x3;
 
+    private SfcScfOfUtils() {
+    }
+
     /**
      * Get a FlowBuilder object that install the table-miss in the classifier
      * table.
@@ -255,13 +258,13 @@ public class SfcScfOfUtils {
 
         VirtualMacAddress vmac = VirtualMacAddress.getForwardAddress(pathId, 0);
 
-        if ((nodeName == null) || (flowKey == null)) {
+        if (nodeName == null || flowKey == null) {
             return null;
         }
 
         Action macDst = SfcOpenflowUtils.createActionSetDlDst(vmac.getHop(startIndex).getValue(), order++);
 
-        Action out = SfcOpenflowUtils.createActionOutPort(Integer.parseInt(outPort), order++);
+        Action out = SfcOpenflowUtils.createActionOutPort(Integer.parseInt(outPort), order);
 
 
         FlowBuilder flowb = new FlowBuilder();
@@ -274,7 +277,6 @@ public class SfcScfOfUtils {
                         .createActionsInstructionBuilder(macDst, out))
                         .build());
         return flowb;
-        //return SfcOpenflowUtils.writeFlowToDataStore(nodeName, flowb);
     }
 
     /**
@@ -296,7 +298,7 @@ public class SfcScfOfUtils {
 
         VirtualMacAddress vmac = VirtualMacAddress.getForwardAddress(pathId, 0);
 
-        if ((nodeName == null) || (flowKey == null)) {
+        if (nodeName == null || flowKey == null) {
             return null;
         }
 
@@ -306,7 +308,7 @@ public class SfcScfOfUtils {
 
         Action macDst = SfcOpenflowUtils.createActionSetDlDst(vmac.getHop(startIndex).getValue(), order++);
 
-        Action out = SfcOpenflowUtils.createActionOutPort(Integer.parseInt(outPort), order++);
+        Action out = SfcOpenflowUtils.createActionOutPort(Integer.parseInt(outPort), order);
 
         FlowBuilder flowb = new FlowBuilder();
         flowb.setId(new FlowId(flowKey))
@@ -319,12 +321,8 @@ public class SfcScfOfUtils {
                         .build());
 
         return flowb;
-        //return SfcOpenflowUtils.writeFlowToDataStore(nodeName, flowb);
-
     }
 
-
-
     /**
      * create classifier out flow for MAC Chaining.
      * The function returns true if successful.
@@ -344,7 +342,7 @@ public class SfcScfOfUtils {
 
         VirtualMacAddress vmac = VirtualMacAddress.getForwardAddress(pathId, 0);
 
-        if ((nodeName == null) || (flowKey == null)) {
+        if (nodeName == null || flowKey == null) {
             return null;
         }
 
@@ -354,7 +352,7 @@ public class SfcScfOfUtils {
 
         //set here the gateway MAC to end the chain
         Action macDst = SfcOpenflowUtils.createActionSetDlDst(gwMac, order++);
-        Action out = SfcOpenflowUtils.createActionOutPort(Integer.parseInt(outPort), order++);
+        Action out = SfcOpenflowUtils.createActionOutPort(Integer.parseInt(outPort), order);
 
         FlowBuilder flowb = new FlowBuilder();
         flowb.setId(new FlowId(flowKey))
@@ -367,7 +365,5 @@ public class SfcScfOfUtils {
                         .build());
 
         return flowb;
-        //return SfcOpenflowUtils.writeFlowToDataStore(nodeName, flowb);
     }
-
 }