use try-with-resource for connectivity testing

Change-Id: Ie5e1674d4a28f47a66a41b449468bd9abe359ecd
diff --git a/providers/netconf/device/src/main/java/org/onosproject/provider/netconf/device/impl/NetconfDeviceProvider.java b/providers/netconf/device/src/main/java/org/onosproject/provider/netconf/device/impl/NetconfDeviceProvider.java
index c66643f..be5a936 100644
--- a/providers/netconf/device/src/main/java/org/onosproject/provider/netconf/device/impl/NetconfDeviceProvider.java
+++ b/providers/netconf/device/src/main/java/org/onosproject/provider/netconf/device/impl/NetconfDeviceProvider.java
@@ -291,7 +291,6 @@
         Device device = deviceService.getDevice(deviceId);
         String ip;
         int port;
-        Socket socket = null;
         if (device != null) {
             ip = device.annotations().value(IPADDRESS);
             port = Integer.parseInt(device.annotations().value(PORT));
@@ -310,22 +309,12 @@
             }
         }
         //test connection to device opening a socket to it.
-        try {
-            socket = new Socket(ip, port);
+        try (Socket socket = new Socket(ip, port)) {
             log.debug("rechability of {}, {}, {}", deviceId, socket.isConnected(), !socket.isClosed());
             return socket.isConnected() && !socket.isClosed();
         } catch (IOException e) {
             log.info("Device {} is not reachable", deviceId);
             return false;
-        } finally {
-            if (socket != null) {
-                try {
-                    socket.close();
-                } catch (IOException e) {
-                    log.debug("Test Socket failed {} ", deviceId);
-                    return false;
-                }
-            }
         }
     }