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

sruehl pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-plc4x.git


The following commit(s) were added to refs/heads/master by this push:
     new e88e8d3  fix sonarqube warnings
e88e8d3 is described below

commit e88e8d36f04c26c70b23df072955e0c4e2154ad2
Author: Sebastian Rühl <sru...@apache.org>
AuthorDate: Thu Feb 22 15:52:15 2018 +0100

    fix sonarqube warnings
---
 .../plc4x/java/utils/rawsockets/RawSocket.java     | 27 ++++++++++++++--------
 1 file changed, 17 insertions(+), 10 deletions(-)

diff --git 
a/plc4j/utils/raw-sockets/src/main/java/org/apache/plc4x/java/utils/rawsockets/RawSocket.java
 
b/plc4j/utils/raw-sockets/src/main/java/org/apache/plc4x/java/utils/rawsockets/RawSocket.java
index 0cbe603..3d23d1f 100644
--- 
a/plc4j/utils/raw-sockets/src/main/java/org/apache/plc4x/java/utils/rawsockets/RawSocket.java
+++ 
b/plc4j/utils/raw-sockets/src/main/java/org/apache/plc4x/java/utils/rawsockets/RawSocket.java
@@ -28,8 +28,13 @@ import org.slf4j.LoggerFactory;
 import java.io.BufferedReader;
 import java.io.IOException;
 import java.io.InputStreamReader;
-import java.net.*;
-import java.util.*;
+import java.net.Inet4Address;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
 import java.util.concurrent.*;
 
 public class RawSocket {
@@ -39,7 +44,7 @@ public class RawSocket {
     private static final int SNAPLEN = 65536;
     private static final int READ_TIMEOUT = 10;
 
-    private static final Map<InetAddress, MacAddress>  arpCache = new 
HashMap<>();
+    private static final Map<InetAddress, MacAddress> arpCache = new 
HashMap<>();
 
     // The id of the protocol we will be communicating in.
     private final int protocolNumber;
@@ -79,11 +84,11 @@ public class RawSocket {
 
             // Check if we can connect directly to the destination.
             FirstHop firstHop = getFirstHop(remoteIpAddress);
-            if(firstHop == null) {
+            if (firstHop == null) {
                 // If this wouldn't work, try to figure out the default
                 // gateway and use that as next hop.
                 InetAddress defaultGatewayAddress = getDefaultGatewayAddress();
-                if(defaultGatewayAddress != null) {
+                if (defaultGatewayAddress != null) {
                     firstHop = getFirstHop(defaultGatewayAddress);
                     if (firstHop == null) {
                         // If this didn't work, we simply can't reach the
@@ -120,7 +125,7 @@ public class RawSocket {
 
             receiveHandle.setFilter(filterString, 
BpfProgram.BpfCompileMode.OPTIMIZE);
             PacketListener packetListener = packet -> {
-                for(RawSocketListener listener : listeners) {
+                for (RawSocketListener listener : listeners) {
                     listener.packetReceived(packet.getRawData());
                 }
             };
@@ -143,8 +148,8 @@ public class RawSocket {
     }
 
     public void write(byte[] rawData) throws RawSocketException {
-        try(PcapHandle sendHandle =
-                nif.openLive(SNAPLEN, 
PcapNetworkInterface.PromiscuousMode.PROMISCUOUS, READ_TIMEOUT)) {
+        try (PcapHandle sendHandle =
+                 nif.openLive(SNAPLEN, 
PcapNetworkInterface.PromiscuousMode.PROMISCUOUS, READ_TIMEOUT)) {
             UnknownPacket.Builder packetBuilder = new UnknownPacket.Builder();
             packetBuilder.rawData(rawData);
 
@@ -191,7 +196,7 @@ public class RawSocket {
     }
 
     private MacAddress getMacAddress(PcapNetworkInterface dev, InetAddress 
localIpAddress, InetAddress remoteIpAddress) throws RawSocketException {
-        if(!arpCache.containsKey(remoteIpAddress)) {
+        if (!arpCache.containsKey(remoteIpAddress)) {
             MacAddress macAddress = lookupMacAddress(dev, localIpAddress, 
remoteIpAddress);
             arpCache.put(remoteIpAddress, macAddress);
             return macAddress;
@@ -267,7 +272,7 @@ public class RawSocket {
                 if (sendHandle.isOpen()) {
                     sendHandle.close();
                 }
-                if(receiveHandle.isOpen()) {
+                if (receiveHandle.isOpen()) {
                     // Terminate the receive loop first.
                     receiveHandle.breakLoop();
                     receiveHandle.close();
@@ -331,6 +336,7 @@ public class RawSocket {
      *
      * @return InetAddress representing the address of the internet gateway.
      */
+    @SuppressWarnings("squid:S1313")
     private InetAddress getDefaultGatewayAddress() {
         try {
             Runtime rt = Runtime.getRuntime();
@@ -362,6 +368,7 @@ public class RawSocket {
                 }
             }
         } catch (IOException e) {
+            logger.debug("error caught", e);
             return null;
         }
 

-- 
To stop receiving notification emails like this one, please contact
sru...@apache.org.

Reply via email to