You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by hu...@apache.org on 2023/05/11 17:30:49 UTC
[plc4x] branch develop updated: fix(plc4j/profinet): Sonar fix regex matching zeo chars
This is an automated email from the ASF dual-hosted git repository.
hutcheb 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 30995f2c95 fix(plc4j/profinet): Sonar fix regex matching zeo chars
30995f2c95 is described below
commit 30995f2c95ce619203815ea85ba778ce8c26856b
Author: Ben Hutcheson <be...@gmail.com>
AuthorDate: Thu May 11 19:25:42 2023 +0200
fix(plc4j/profinet): Sonar fix regex matching zeo chars
---
.../plc4x/java/profinet/config/ProfinetConfiguration.java | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)
diff --git a/plc4j/drivers/profinet/src/main/java/org/apache/plc4x/java/profinet/config/ProfinetConfiguration.java b/plc4j/drivers/profinet/src/main/java/org/apache/plc4x/java/profinet/config/ProfinetConfiguration.java
index 31e6885406..03aaa173a5 100644
--- a/plc4j/drivers/profinet/src/main/java/org/apache/plc4x/java/profinet/config/ProfinetConfiguration.java
+++ b/plc4j/drivers/profinet/src/main/java/org/apache/plc4x/java/profinet/config/ProfinetConfiguration.java
@@ -70,7 +70,7 @@ public class ProfinetConfiguration implements Configuration, RawSocketTransportC
@Required
@ConfigurationParameter("gsddirectory")
@ParameterConverter(ProfinetGsdFileConvertor.class)
- static protected GsdFileMap gsdFiles;
+ protected static GsdFileMap gsdFiles;
@ConfigurationParameter("sendclockfactor")
@IntDefaultValue(32)
@@ -90,7 +90,7 @@ public class ProfinetConfiguration implements Configuration, RawSocketTransportC
public static class ProfinetDeviceConvertor implements ConfigurationParameterConverter<ProfinetDevices> {
- public static final String DEVICE_STRING = "((?<devicename>[\\w- ]*){1}[, ]+(?<deviceaccess>[\\w ]*){1}[, ]+\\((?<submodules>[\\w, ]*)\\)[, ]*(?<ipaddress>[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+)?)";
+ public static final String DEVICE_STRING = "((?<devicename>[\\w- ]+)[, ]+(?<deviceaccess>[\\w ]+)[, ]+\\((?<submodules>[\\w, ]*)\\)[, ]*(?<ipaddress>\\d+\\.\\d+\\.\\d+\\.\\d+)?)";
public static final String DEVICE_ARRAY_STRING = "^\\[(?:(\\[" + DEVICE_STRING + "{1}\\])[, ]?)+\\]";
public static final Pattern DEVICE_NAME_ARRAY_PATTERN = Pattern.compile(DEVICE_ARRAY_STRING);
public static final Pattern DEVICE_PARAMETERS = Pattern.compile(DEVICE_STRING);
@@ -145,8 +145,9 @@ public class ProfinetConfiguration implements Configuration, RawSocketTransportC
@Override
public GsdFileMap convert(String value) {
HashMap<String, ProfinetISO15745Profile> gsdFiles = new HashMap<>();
+ DirectoryStream<Path> stream = null;
try {
- DirectoryStream<Path> stream = Files.newDirectoryStream(Paths.get(value));
+ stream = Files.newDirectoryStream(Paths.get(value));
XmlMapper xmlMapper = new XmlMapper();
for (Path file : stream) {
try {
@@ -160,6 +161,14 @@ public class ProfinetConfiguration implements Configuration, RawSocketTransportC
}
} catch (IOException e) {
throw new RuntimeException("GSDML File directory is un-readable");
+ } finally {
+ try {
+ if (stream != null) {
+ stream.close();
+ }
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
}
return new GsdFileMap(gsdFiles);
}