You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by cd...@apache.org on 2020/02/17 15:52:32 UTC
[plc4x] branch develop updated: - Addressed some major SonarCloud
issues.
This is an automated email from the ASF dual-hosted git repository.
cdutz pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git
The following commit(s) were added to refs/heads/develop by this push:
new e1dc816 - Addressed some major SonarCloud issues.
e1dc816 is described below
commit e1dc816dcc49ab68bdaa21d9ee1d1315e7da252e
Author: Christofer Dutz <ch...@c-ware.de>
AuthorDate: Mon Feb 17 16:52:24 2020 +0100
- Addressed some major SonarCloud issues.
---
.../freemarker/FreemarkerLanguageOutput.java | 15 +-
.../plc4x/java/knxnetip/ets5/Ets5Parser.java | 164 ++++++++++-----------
.../plc4x/java/knxnetip/ets5/model/Ets5Model.java | 4 +-
.../robot/controllers/RobotController.java | 8 +-
.../apache/plc4x/camel/Plc4XPollingConsumer.java | 10 +-
.../apache/plc4x/nifi/Plc4xSourceProcessor.java | 7 +-
.../main/java/org/apache/plc4x/logstash/Plc4x.java | 1 +
.../plc4x/java/spi/generation/ReadBuffer.java | 2 +-
.../utils/rawsockets/attic/RawEthernetSocket.java | 6 +-
.../java/utils/rawsockets/attic/RawIpSocket.java | 22 ++-
.../server/s7/protocol/S7Step7ServerProtocol.java | 4 +
.../watertank/WaterTankSimulationModule.java | 1 +
.../s7/readwrite/protocol/S7ProtocolLogic.java | 5 +-
.../adapters/source/bacnetip/BacNetIpAdapter.java | 6 +-
14 files changed, 145 insertions(+), 110 deletions(-)
diff --git a/build-utils/language-base-freemarker/src/main/java/org/apache/plc4x/plugins/codegenerator/protocol/freemarker/FreemarkerLanguageOutput.java b/build-utils/language-base-freemarker/src/main/java/org/apache/plc4x/plugins/codegenerator/protocol/freemarker/FreemarkerLanguageOutput.java
index 98e364d..4c5a806 100644
--- a/build-utils/language-base-freemarker/src/main/java/org/apache/plc4x/plugins/codegenerator/protocol/freemarker/FreemarkerLanguageOutput.java
+++ b/build-utils/language-base-freemarker/src/main/java/org/apache/plc4x/plugins/codegenerator/protocol/freemarker/FreemarkerLanguageOutput.java
@@ -141,14 +141,15 @@ public abstract class FreemarkerLanguageOutput implements LanguageOutput {
}
// Output the rest to that file
- BufferedWriter outputFileWriter = Files.newBufferedWriter(
- outputFile.toPath(), StandardCharsets.UTF_8);
- String line;
- while ((line = input.readLine()) != null) {
- outputFileWriter.write(line);
- outputFileWriter.newLine();
+ try(BufferedWriter outputFileWriter = Files.newBufferedWriter(
+ outputFile.toPath(), StandardCharsets.UTF_8)) {
+ String line;
+ while ((line = input.readLine()) != null) {
+ outputFileWriter.write(line);
+ outputFileWriter.newLine();
+ }
+ outputFileWriter.flush();
}
- outputFileWriter.flush();
}
}
diff --git a/plc4j/drivers/knxnetip/src/main/java/org/apache/plc4x/java/knxnetip/ets5/Ets5Parser.java b/plc4j/drivers/knxnetip/src/main/java/org/apache/plc4x/java/knxnetip/ets5/Ets5Parser.java
index 2321188..4465461 100644
--- a/plc4j/drivers/knxnetip/src/main/java/org/apache/plc4x/java/knxnetip/ets5/Ets5Parser.java
+++ b/plc4j/drivers/knxnetip/src/main/java/org/apache/plc4x/java/knxnetip/ets5/Ets5Parser.java
@@ -48,89 +48,89 @@ public class Ets5Parser {
XPathFactory xPathFactory = XPathFactory.newInstance();
XPath xPath = xPathFactory.newXPath();
- ZipFile zipFile = new ZipFile(knxprojFile);
-
- ////////////////////////////////////////////////////////////////////////////////
- // File containing the information on the type of encoding used for group addresses.
- ////////////////////////////////////////////////////////////////////////////////
- ZipArchiveEntry projectHeaderFile = zipFile.getEntry("P-05CD/project.xml");
- if(projectHeaderFile == null) {
- throw new RuntimeException("Error accessing project header file.");
+ try (ZipFile zipFile = new ZipFile(knxprojFile)) {
+
+ ////////////////////////////////////////////////////////////////////////////////
+ // File containing the information on the type of encoding used for group addresses.
+ ////////////////////////////////////////////////////////////////////////////////
+ ZipArchiveEntry projectHeaderFile = zipFile.getEntry("P-05CD/project.xml");
+ if (projectHeaderFile == null) {
+ throw new RuntimeException("Error accessing project header file.");
+ }
+ Document projectHeaderDoc = builder.parse(zipFile.getInputStream(projectHeaderFile));
+ final XPathExpression xpathGroupAddressStyle = xPath.compile("/KNX/Project/ProjectInformation/@GroupAddressStyle");
+ Attr groupAddressStyle = (Attr) xpathGroupAddressStyle.evaluate(projectHeaderDoc, XPathConstants.NODE);
+ byte groupAddressStyleCode = getGroupAddressLevel(groupAddressStyle.getTextContent());
+
+ ////////////////////////////////////////////////////////////////////////////////
+ // General information on the type of encoding and the value ranges.
+ ////////////////////////////////////////////////////////////////////////////////
+ ZipArchiveEntry knxMasterDataFile = zipFile.getEntry("knx_master.xml");
+ if (knxMasterDataFile == null) {
+ throw new RuntimeException("Error accessing KNX master file.");
+ }
+ Document knxMasterDoc = builder.parse(zipFile.getInputStream(knxMasterDataFile));
+ final XPathExpression xpathDatapointSubtype = xPath.compile("//DatapointSubtype");
+ NodeList datapointSubtypeNodes = (NodeList) xpathDatapointSubtype.evaluate(knxMasterDoc, XPathConstants.NODESET);
+ Map<String, AddressType> addressTypes = new HashMap<>();
+ for (int i = 0; i < datapointSubtypeNodes.getLength(); i++) {
+ final Element datapointSubtypeNode = (Element) datapointSubtypeNodes.item(i);
+ final String id = datapointSubtypeNode.getAttribute("Id");
+ final int subType = Integer.parseInt(datapointSubtypeNode.getAttribute("Number"));
+ final int mainType = Integer.parseInt(
+ ((Element) datapointSubtypeNode.getParentNode().getParentNode()).getAttribute("Number"));
+ final String name = datapointSubtypeNode.getAttribute("Text");
+ addressTypes.put(id, new AddressType(id, mainType, subType, name));
+ }
+
+ ////////////////////////////////////////////////////////////////////////////////
+ // File containing all the information about group addresses used, their names, types etc.
+ ////////////////////////////////////////////////////////////////////////////////
+ ZipArchiveEntry projectFile = zipFile.getEntry("P-05CD/0.xml");
+ if (projectFile == null) {
+ throw new RuntimeException("Error accessing project file.");
+ }
+ Document projectDoc = builder.parse(zipFile.getInputStream(projectFile));
+
+ final Map<String, Function> groupAddressRefs = new HashMap();
+ final XPathExpression xpathGroupAddressRef = xPath.compile("//GroupAddressRef");
+ NodeList groupAddressRefNodes = (NodeList) xpathGroupAddressRef.evaluate(projectDoc, XPathConstants.NODESET);
+ for (int i = 0; i < groupAddressRefNodes.getLength(); i++) {
+ final Element groupAddressRefNode = (Element) groupAddressRefNodes.item(i);
+ final String refId = groupAddressRefNode.getAttribute("RefId");
+ final Element functionNode = (Element) groupAddressRefNode.getParentNode();
+ final String functionName = functionNode.getAttribute("Name");
+ // Function Type information is stored in knx_master.xml (//FunctionType[@id='functionTypeId']
+ final String functionTypeId = functionNode.getAttribute("Type");
+ final Element spaceNode = (Element) functionNode.getParentNode();
+ final String spaceName = spaceNode.getAttribute("Name");
+
+ final Function function = new Function(refId, functionName, functionTypeId, spaceName);
+ groupAddressRefs.put(refId, function);
+ }
+
+ final XPathExpression xpathGroupAddresses = xPath.compile("//GroupAddress");
+ NodeList groupAddressNodes = (NodeList) xpathGroupAddresses.evaluate(projectDoc, XPathConstants.NODESET);
+ Map<String, GroupAddress> groupAddresses = new HashMap<>();
+ for (int i = 0; i < groupAddressNodes.getLength(); i++) {
+ final Element groupAddressNode = (Element) groupAddressNodes.item(i);
+
+ final String id = groupAddressNode.getAttribute("Id");
+ final Function function = groupAddressRefs.get(id);
+
+ final int addressInt = Integer.parseInt(groupAddressNode.getAttribute("Address"));
+ final String knxGroupAddress = Ets5Model.parseGroupAddress(groupAddressStyleCode, addressInt);
+
+ final String name = groupAddressNode.getAttribute("Name");
+
+ final String typeString = groupAddressNode.getAttribute("DatapointType");
+ final AddressType addressType = addressTypes.get(typeString);
+
+ GroupAddress groupAddress = new GroupAddress(knxGroupAddress, name, addressType, function);
+ groupAddresses.put(knxGroupAddress, groupAddress);
+ }
+ return new Ets5Model(groupAddressStyleCode, groupAddresses);
}
- Document projectHeaderDoc = builder.parse(zipFile.getInputStream(projectHeaderFile));
- final XPathExpression xpathGroupAddressStyle = xPath.compile("/KNX/Project/ProjectInformation/@GroupAddressStyle");
- Attr groupAddressStyle = (Attr) xpathGroupAddressStyle.evaluate(projectHeaderDoc, XPathConstants.NODE);
- byte groupAddressStyleCode = getGroupAddressLevel(groupAddressStyle.getTextContent());
-
- ////////////////////////////////////////////////////////////////////////////////
- // General information on the type of encoding and the value ranges.
- ////////////////////////////////////////////////////////////////////////////////
- ZipArchiveEntry knxMasterDataFile = zipFile.getEntry("knx_master.xml");
- if(knxMasterDataFile == null) {
- throw new RuntimeException("Error accessing KNX master file.");
- }
- Document knxMasterDoc = builder.parse(zipFile.getInputStream(knxMasterDataFile));
- final XPathExpression xpathDatapointSubtype = xPath.compile("//DatapointSubtype");
- NodeList datapointSubtypeNodes = (NodeList) xpathDatapointSubtype.evaluate(knxMasterDoc, XPathConstants.NODESET);
- Map<String, AddressType> addressTypes = new HashMap<>();
- for(int i = 0; i < datapointSubtypeNodes.getLength(); i++) {
- final Element datapointSubtypeNode = (Element) datapointSubtypeNodes.item(i);
- final String id = datapointSubtypeNode.getAttribute("Id");
- final int subType = Integer.parseInt(datapointSubtypeNode.getAttribute("Number"));
- final int mainType = Integer.parseInt(
- ((Element) datapointSubtypeNode.getParentNode().getParentNode()).getAttribute("Number"));
- final String name = datapointSubtypeNode.getAttribute("Text");
- addressTypes.put(id, new AddressType(id, mainType, subType, name));
- }
-
- ////////////////////////////////////////////////////////////////////////////////
- // File containing all the information about group addresses used, their names, types etc.
- ////////////////////////////////////////////////////////////////////////////////
- ZipArchiveEntry projectFile = zipFile.getEntry("P-05CD/0.xml");
- if(projectFile == null) {
- throw new RuntimeException("Error accessing project file.");
- }
- Document projectDoc = builder.parse(zipFile.getInputStream(projectFile));
-
- final Map<String, Function> groupAddressRefs = new HashMap();
- final XPathExpression xpathGroupAddressRef = xPath.compile("//GroupAddressRef");
- NodeList groupAddressRefNodes = (NodeList) xpathGroupAddressRef.evaluate(projectDoc, XPathConstants.NODESET);
- for(int i = 0; i < groupAddressRefNodes.getLength(); i++) {
- final Element groupAddressRefNode = (Element) groupAddressRefNodes.item(i);
- final String refId = groupAddressRefNode.getAttribute("RefId");
- final Element functionNode = (Element) groupAddressRefNode.getParentNode();
- final String functionName = functionNode.getAttribute("Name");
- // Function Type information is stored in knx_master.xml (//FunctionType[@id='functionTypeId']
- final String functionTypeId = functionNode.getAttribute("Type");
- final Element spaceNode = (Element) functionNode.getParentNode();
- final String spaceName = spaceNode.getAttribute("Name");
-
- final Function function = new Function(refId, functionName, functionTypeId, spaceName);
- groupAddressRefs.put(refId, function);
- }
-
- final XPathExpression xpathGroupAddresses = xPath.compile("//GroupAddress");
- NodeList groupAddressNodes = (NodeList) xpathGroupAddresses.evaluate(projectDoc, XPathConstants.NODESET);
- Map<String, GroupAddress> groupAddresses = new HashMap<>();
- for(int i = 0; i < groupAddressNodes.getLength(); i++) {
- final Element groupAddressNode = (Element) groupAddressNodes.item(i);
-
- final String id = groupAddressNode.getAttribute("Id");
- final Function function = groupAddressRefs.get(id);
-
- final int addressInt = Integer.parseInt(groupAddressNode.getAttribute("Address"));
- final String knxGroupAddress = Ets5Model.parseGroupAddress(groupAddressStyleCode, addressInt);
-
- final String name = groupAddressNode.getAttribute("Name");
-
- final String typeString = groupAddressNode.getAttribute("DatapointType");
- final AddressType addressType = addressTypes.get(typeString);
-
- GroupAddress groupAddress = new GroupAddress(knxGroupAddress, name, addressType, function);
- groupAddresses.put(knxGroupAddress, groupAddress);
- }
-
- return new Ets5Model(groupAddressStyleCode, groupAddresses);
} catch (IOException e) {
// Zip and Xml Stuff
e.printStackTrace();
diff --git a/plc4j/drivers/knxnetip/src/main/java/org/apache/plc4x/java/knxnetip/ets5/model/Ets5Model.java b/plc4j/drivers/knxnetip/src/main/java/org/apache/plc4x/java/knxnetip/ets5/model/Ets5Model.java
index 222a91b..60a5ced 100644
--- a/plc4j/drivers/knxnetip/src/main/java/org/apache/plc4x/java/knxnetip/ets5/model/Ets5Model.java
+++ b/plc4j/drivers/knxnetip/src/main/java/org/apache/plc4x/java/knxnetip/ets5/model/Ets5Model.java
@@ -40,7 +40,7 @@ public class Ets5Model {
}
public static String parseGroupAddress(byte groupAddressType, byte[] addressBytes) {
- int addressInt = (addressBytes[0] << 8) | addressBytes[1];
+ int addressInt = (addressBytes[0] << 8) | (addressBytes[1] & 0xFF);
return parseGroupAddress(groupAddressType, addressInt);
}
@@ -65,7 +65,7 @@ public class Ets5Model {
}
public String parseGroupAddress(byte[] addressBytes) {
- int addressInt = (addressBytes[0] << 8) | addressBytes[1];
+ int addressInt = (addressBytes[0] << 8) | (addressBytes[1] & 0xFF);
return parseGroupAddress(getGroupAddressType(), addressInt);
}
diff --git a/plc4j/examples/hello-webapp/service/src/main/java/org/apache/plc4x/examples/robot/controllers/RobotController.java b/plc4j/examples/hello-webapp/service/src/main/java/org/apache/plc4x/examples/robot/controllers/RobotController.java
index 0b6c9bc..81cb408 100644
--- a/plc4j/examples/hello-webapp/service/src/main/java/org/apache/plc4x/examples/robot/controllers/RobotController.java
+++ b/plc4j/examples/hello-webapp/service/src/main/java/org/apache/plc4x/examples/robot/controllers/RobotController.java
@@ -61,7 +61,7 @@ public class RobotController {
@RequestMapping("move")
public boolean move(@RequestParam(value="direction", defaultValue="stop") String direction) {
- logger.info("Move in direction: " + direction);
+ logger.info(String.format("Move in direction: %s", direction));
byte state;
switch (direction) {
case "forward-right":
@@ -96,7 +96,11 @@ public class RobotController {
PlcWriteRequest updateRequest = connection.writeRequestBuilder().addItem("state", addressString, state).build();
updateRequest.execute().get(2000, TimeUnit.MILLISECONDS);
return true;
- } catch (InterruptedException | ExecutionException | TimeoutException e) {
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ logger.error("Caught Exception:", e);
+ return false;
+ } catch(ExecutionException | TimeoutException e) {
logger.error("Caught Exception:", e);
return false;
}
diff --git a/plc4j/integrations/apache-camel/src/main/java/org/apache/plc4x/camel/Plc4XPollingConsumer.java b/plc4j/integrations/apache-camel/src/main/java/org/apache/plc4x/camel/Plc4XPollingConsumer.java
index 5467711..67c4c36 100644
--- a/plc4j/integrations/apache-camel/src/main/java/org/apache/plc4x/camel/Plc4XPollingConsumer.java
+++ b/plc4j/integrations/apache-camel/src/main/java/org/apache/plc4x/camel/Plc4XPollingConsumer.java
@@ -80,7 +80,10 @@ public class Plc4XPollingConsumer extends ServiceSupport implements PollingConsu
try {
PlcReadResponse plcReadResponse = read.get();
exchange.getIn().setBody(unwrapIfSingle(plcReadResponse.getAllObjects("default")));
- } catch (InterruptedException | ExecutionException e) {
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ exchange.setException(e);
+ } catch (ExecutionException e) {
exchange.setException(e);
}
return exchange;
@@ -98,7 +101,10 @@ public class Plc4XPollingConsumer extends ServiceSupport implements PollingConsu
try {
PlcReadResponse plcReadResponse = read.get(timeout, TimeUnit.MILLISECONDS);
exchange.getIn().setBody(unwrapIfSingle(plcReadResponse.getAllObjects("default")));
- } catch (InterruptedException | ExecutionException | TimeoutException e) {
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ exchange.setException(e);
+ } catch (ExecutionException | TimeoutException e) {
exchange.setException(e);
}
return exchange;
diff --git a/plc4j/integrations/apache-nifi/nifi-plc4x-processors/src/main/java/org/apache/plc4x/nifi/Plc4xSourceProcessor.java b/plc4j/integrations/apache-nifi/nifi-plc4x-processors/src/main/java/org/apache/plc4x/nifi/Plc4xSourceProcessor.java
index f11a263..d043baf 100644
--- a/plc4j/integrations/apache-nifi/nifi-plc4x-processors/src/main/java/org/apache/plc4x/nifi/Plc4xSourceProcessor.java
+++ b/plc4j/integrations/apache-nifi/nifi-plc4x-processors/src/main/java/org/apache/plc4x/nifi/Plc4xSourceProcessor.java
@@ -62,7 +62,7 @@ public class Plc4xSourceProcessor extends BasePlc4xProcessor {
});
PlcReadRequest readRequest = builder.build();
PlcReadResponse response = readRequest.execute().get();
- Map attributes = new HashMap<String, String>();
+ Map<String, String> attributes = new HashMap<>();
for (String fieldName : response.getFieldNames()) {
for(int i = 0; i < response.getNumberOfValues(fieldName); i++) {
Object value = response.getObject(fieldName, i);
@@ -70,7 +70,10 @@ public class Plc4xSourceProcessor extends BasePlc4xProcessor {
}
}
flowFile = session.putAllAttributes(flowFile, attributes);
- } catch (InterruptedException | ExecutionException e) {
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ throw new ProcessException(e);
+ } catch (ExecutionException e) {
throw new ProcessException(e);
}
session.transfer(flowFile, SUCCESS);
diff --git a/plc4j/integrations/logstash-plugin/src/main/java/org/apache/plc4x/logstash/Plc4x.java b/plc4j/integrations/logstash-plugin/src/main/java/org/apache/plc4x/logstash/Plc4x.java
index 381ec4d..cb9eb53 100644
--- a/plc4j/integrations/logstash-plugin/src/main/java/org/apache/plc4x/logstash/Plc4x.java
+++ b/plc4j/integrations/logstash-plugin/src/main/java/org/apache/plc4x/logstash/Plc4x.java
@@ -141,6 +141,7 @@ public class Plc4x implements Input {
Thread.sleep(1000);
// or maybe just yield(); ?
} catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
logger.severe("Error thead sleep plc4x plugin: "+ e);
}
}
diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/generation/ReadBuffer.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/generation/ReadBuffer.java
index 481f4e1..4954135 100644
--- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/generation/ReadBuffer.java
+++ b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/generation/ReadBuffer.java
@@ -40,7 +40,7 @@ public class ReadBuffer {
ArrayByteInput abi = new ArrayByteInput(input);
this.bi = new MyDefaultBitInput(abi);
this.littleEndian = littleEndian;
- this.totalBytes = input.length * 8;
+ this.totalBytes = (long) input.length * 8;
}
public int getPos() {
diff --git a/plc4j/utils/raw-sockets/src/main/java/org/apache/plc4x/java/utils/rawsockets/attic/RawEthernetSocket.java b/plc4j/utils/raw-sockets/src/main/java/org/apache/plc4x/java/utils/rawsockets/attic/RawEthernetSocket.java
index d40eaa1..c2d73be 100644
--- a/plc4j/utils/raw-sockets/src/main/java/org/apache/plc4x/java/utils/rawsockets/attic/RawEthernetSocket.java
+++ b/plc4j/utils/raw-sockets/src/main/java/org/apache/plc4x/java/utils/rawsockets/attic/RawEthernetSocket.java
@@ -98,7 +98,11 @@ public class RawEthernetSocket {
pool.execute(() -> {
try {
receiveHandle.loop(-1, packetListener);
- } catch (PcapNativeException | InterruptedException | NotOpenException e) {
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ logger.error("Error receiving packet for protocol {} from MAC address {}",
+ etherType.valueAsString(), remoteMacAddress, e);
+ } catch (PcapNativeException | NotOpenException e) {
logger.error("Error receiving packet for protocol {} from MAC address {}",
etherType.valueAsString(), remoteMacAddress, e);
}
diff --git a/plc4j/utils/raw-sockets/src/main/java/org/apache/plc4x/java/utils/rawsockets/attic/RawIpSocket.java b/plc4j/utils/raw-sockets/src/main/java/org/apache/plc4x/java/utils/rawsockets/attic/RawIpSocket.java
index b53efad..4fa4215 100644
--- a/plc4j/utils/raw-sockets/src/main/java/org/apache/plc4x/java/utils/rawsockets/attic/RawIpSocket.java
+++ b/plc4j/utils/raw-sockets/src/main/java/org/apache/plc4x/java/utils/rawsockets/attic/RawIpSocket.java
@@ -133,7 +133,11 @@ public class RawIpSocket {
pool.execute(() -> {
try {
receiveHandle.loop(-1, packetListener);
- } catch (PcapNativeException | InterruptedException | NotOpenException e) {
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ logger.error("Error receiving packet for protocol {} from MAC address {}",
+ protocolNumber, firstHopMacAddress, e);
+ } catch (PcapNativeException | NotOpenException e) {
logger.error("Error receiving packet for protocol {} from MAC address {}",
protocolNumber, firstHopMacAddress, e);
}
@@ -205,11 +209,11 @@ public class RawIpSocket {
}
private MacAddress lookupMacAddress(PcapNetworkInterface dev, InetAddress localIpAddress, InetAddress remoteIpAddress) throws RawSocketException {
- try {
- PcapHandle receiveHandle =
- dev.openLive(SNAPLEN, PcapNetworkInterface.PromiscuousMode.PROMISCUOUS, READ_TIMEOUT);
- PcapHandle sendHandle =
- dev.openLive(SNAPLEN, PcapNetworkInterface.PromiscuousMode.PROMISCUOUS, READ_TIMEOUT);
+ try (PcapHandle receiveHandle =
+ dev.openLive(SNAPLEN, PcapNetworkInterface.PromiscuousMode.PROMISCUOUS, READ_TIMEOUT);
+ PcapHandle sendHandle =
+ dev.openLive(SNAPLEN, PcapNetworkInterface.PromiscuousMode.PROMISCUOUS, READ_TIMEOUT)){
+
try {
// Setup the filter to accept only the arp packets sent back to the current
// host from the address of the remote host we wanted to get the mac address
@@ -281,7 +285,11 @@ public class RawIpSocket {
receiveHandle.close();
}
}
- } catch (PcapNativeException | InterruptedException | ExecutionException | NotOpenException e) {
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ throw new RawSocketException("Error looking up MAC address for ip address " +
+ remoteIpAddress.getHostAddress() + " on device " + dev.getName(), e);
+ } catch (PcapNativeException | ExecutionException | NotOpenException e) {
throw new RawSocketException("Error looking up MAC address for ip address " +
remoteIpAddress.getHostAddress() + " on device " + dev.getName(), e);
}
diff --git a/sandbox/plc-simulator/src/main/java/org/apache/plc4x/simulator/server/s7/protocol/S7Step7ServerProtocol.java b/sandbox/plc-simulator/src/main/java/org/apache/plc4x/simulator/server/s7/protocol/S7Step7ServerProtocol.java
index 35a3142..809fbb7 100644
--- a/sandbox/plc-simulator/src/main/java/org/apache/plc4x/simulator/server/s7/protocol/S7Step7ServerProtocol.java
+++ b/sandbox/plc-simulator/src/main/java/org/apache/plc4x/simulator/server/s7/protocol/S7Step7ServerProtocol.java
@@ -77,6 +77,10 @@ public class S7Step7ServerProtocol extends ChannelInboundHandlerAdapter {
return;
}
}
+ if(proposedTpduSize == null) {
+ LOGGER.error("Missing COTP Connection-Request Parameter Tpdu Size");
+ return;
+ }
remoteReference = cotpConnectionRequest.getSourceReference();
protocolClass = cotpConnectionRequest.getProtocolClass();
diff --git a/sandbox/plc-simulator/src/main/java/org/apache/plc4x/simulator/simulation/watertank/WaterTankSimulationModule.java b/sandbox/plc-simulator/src/main/java/org/apache/plc4x/simulator/simulation/watertank/WaterTankSimulationModule.java
index 8b5ba9c..b41e5dd 100644
--- a/sandbox/plc-simulator/src/main/java/org/apache/plc4x/simulator/simulation/watertank/WaterTankSimulationModule.java
+++ b/sandbox/plc-simulator/src/main/java/org/apache/plc4x/simulator/simulation/watertank/WaterTankSimulationModule.java
@@ -53,6 +53,7 @@ public class WaterTankSimulationModule implements SimulationModule {
context.put(PROP_WATER_LEVEL, ((Integer) context.get(PROP_WATER_LEVEL)) + 1);
TimeUnit.MILLISECONDS.sleep(100);
} catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
e.printStackTrace();
}
}
diff --git a/sandbox/test-java-s7-driver/src/main/java/org/apache/plc4x/java/s7/readwrite/protocol/S7ProtocolLogic.java b/sandbox/test-java-s7-driver/src/main/java/org/apache/plc4x/java/s7/readwrite/protocol/S7ProtocolLogic.java
index e2505dc..d83939d 100644
--- a/sandbox/test-java-s7-driver/src/main/java/org/apache/plc4x/java/s7/readwrite/protocol/S7ProtocolLogic.java
+++ b/sandbox/test-java-s7-driver/src/main/java/org/apache/plc4x/java/s7/readwrite/protocol/S7ProtocolLogic.java
@@ -674,7 +674,10 @@ public class S7ProtocolLogic extends Plc4xProtocolBase<TPKTPacket> implements Ha
} else {
try {
subResult = Either.left(childFuture.get());
- } catch (InterruptedException | ExecutionException e) {
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ e.printStackTrace();
+ } catch (ExecutionException e) {
e.printStackTrace();
}
}
diff --git a/sandbox/test-streampipes-plc4x-adapters/src/main/java/org/apache/plc4x/java/streampipes/adapters/source/bacnetip/BacNetIpAdapter.java b/sandbox/test-streampipes-plc4x-adapters/src/main/java/org/apache/plc4x/java/streampipes/adapters/source/bacnetip/BacNetIpAdapter.java
index b99dcc1..57d65e8 100644
--- a/sandbox/test-streampipes-plc4x-adapters/src/main/java/org/apache/plc4x/java/streampipes/adapters/source/bacnetip/BacNetIpAdapter.java
+++ b/sandbox/test-streampipes-plc4x-adapters/src/main/java/org/apache/plc4x/java/streampipes/adapters/source/bacnetip/BacNetIpAdapter.java
@@ -358,14 +358,14 @@ public class BacNetIpAdapter extends SpecificDataStreamAdapter {
StaticPropertyAlternatives sources = (StaticPropertyAlternatives) extractor.getStaticPropertyByName("source");
final Optional<StaticPropertyAlternative> selectedAlternative = sources.getAlternatives().stream().filter(
- staticPropertyAlternative -> staticPropertyAlternative.getSelected()).findFirst();
+ StaticPropertyAlternative::getSelected).findFirst();
if (selectedAlternative.isPresent()) {
final StaticPropertyAlternative staticPropertyAlternative = selectedAlternative.get();
if ("device".equals(staticPropertyAlternative.getInternalName())) {
final Optional<Option> first =
((OneOfStaticProperty) staticPropertyAlternative.getStaticProperty()).getOptions().stream().filter(
- option -> option.isSelected()).findFirst();
- deviceName = first.get().getName();
+ Option::isSelected).findFirst();
+ deviceName = first.isPresent() ? first.get().getName() : "Unknown";
} else {
pcapFile = ((FileStaticProperty) staticPropertyAlternative.getStaticProperty()).getLocationPath();
}