You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by jf...@apache.org on 2019/03/29 10:37:35 UTC
[incubator-plc4x] branch feature/PLC4X-108-ping-method updated:
Try-with-resource as suggested in PR Review.
This is an automated email from the ASF dual-hosted git repository.
jfeinauer pushed a commit to branch feature/PLC4X-108-ping-method
in repository https://gitbox.apache.org/repos/asf/incubator-plc4x.git
The following commit(s) were added to refs/heads/feature/PLC4X-108-ping-method by this push:
new 395887a Try-with-resource as suggested in PR Review.
395887a is described below
commit 395887a7e7e83e6f58577ab7161a54bac9d50958
Author: julian <j....@pragmaticminds.de>
AuthorDate: Fri Mar 29 11:37:27 2019 +0100
Try-with-resource as suggested in PR Review.
---
.../plc4x/java/base/connection/AbstractPlcConnection.java | 11 +----------
1 file changed, 1 insertion(+), 10 deletions(-)
diff --git a/plc4j/protocols/driver-bases/base/src/main/java/org/apache/plc4x/java/base/connection/AbstractPlcConnection.java b/plc4j/protocols/driver-bases/base/src/main/java/org/apache/plc4x/java/base/connection/AbstractPlcConnection.java
index ba7cca8..72010e2 100644
--- a/plc4j/protocols/driver-bases/base/src/main/java/org/apache/plc4x/java/base/connection/AbstractPlcConnection.java
+++ b/plc4j/protocols/driver-bases/base/src/main/java/org/apache/plc4x/java/base/connection/AbstractPlcConnection.java
@@ -88,21 +88,12 @@ public abstract class AbstractPlcConnection implements PlcConnection, PlcConnect
throw new NotImplementedException("Tries to check the connection with ping, " +
"but no Socket Address is given!");
}
- Socket s = null;
- try {
- s = new Socket();
+ try (Socket s = new Socket()) {
s.connect(address.get(), timeout);
return true;
} catch (Exception e) {
LOGGER.debug("Unable to ping PLC", e);
return false;
- } finally {
- if (s != null) {
- try {
- s.close();
- } catch (Exception e) {
- }
- }
}
}