From 12bfbc7672e6067b279dabc769ee46da80d6c242 Mon Sep 17 00:00:00 2001 From: Sergey Ponomarev Date: Sat, 4 Oct 2025 18:58:10 +0300 Subject: [PATCH 1/2] Use Paths.get() to avoid concatenation with File.separator --- .../org/jivesoftware/smack/util/TLSUtils.java | 5 +++-- .../smackx/formtypes/FormFieldRegistry.java | 4 +--- .../debugger/StandardSinttestDebugger.java | 17 ++++++++--------- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/smack-core/src/main/java/org/jivesoftware/smack/util/TLSUtils.java b/smack-core/src/main/java/org/jivesoftware/smack/util/TLSUtils.java index f28f3a72b7..9d56848c56 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/util/TLSUtils.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/util/TLSUtils.java @@ -22,6 +22,7 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; +import java.nio.file.Paths; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.security.cert.Certificate; @@ -217,8 +218,8 @@ public X509Certificate[] getAcceptedIssuers() { static { String javaHome = System.getProperty("java.home"); - String defaultTruststorePath = javaHome + File.separator + "lib" + File.separator + "security" + File.separator + "cacerts"; - DEFAULT_TRUSTSTORE_PATH = new File(defaultTruststorePath); + var defaultTruststorePath = Paths.get(javaHome, "lib", "security", "cacerts"); + DEFAULT_TRUSTSTORE_PATH = defaultTruststorePath.toFile(); } public static FileInputStream getDefaultTruststoreStreamIfPossible() { diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/formtypes/FormFieldRegistry.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/formtypes/FormFieldRegistry.java index c4bbfef4a0..c22555c0e2 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/formtypes/FormFieldRegistry.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/formtypes/FormFieldRegistry.java @@ -16,7 +16,6 @@ */ package org.jivesoftware.smackx.formtypes; -import java.io.File; import java.io.IOException; import java.io.InputStream; import java.net.URISyntaxException; @@ -112,8 +111,7 @@ private static void loadFormFieldRegistryEntries() throws IOException, IllegalSt if (url.getProtocol().equals("file") && !url.getPath().endsWith(".jar")) { var path = Paths.get(url.toURI()); if (!Files.isDirectory(path)) throw new IllegalStateException("Code source location " + url + " is not a directory"); - var prefix = path.toString() + File.separator + "org.igniterealtime.smack" + File.separator + "xdata" - + File.separator + "form-registry" + File.separator; + var prefix = Paths.get(path.toString(), "org.igniterealtime.smack", "xdata", "form-registry").toString(); try (var walk = Files.walk(path)) { var files = walk.filter(Files::isRegularFile) diff --git a/smack-integration-test/src/main/java/org/igniterealtime/smack/inttest/debugger/StandardSinttestDebugger.java b/smack-integration-test/src/main/java/org/igniterealtime/smack/inttest/debugger/StandardSinttestDebugger.java index 690f58b819..46107256fc 100644 --- a/smack-integration-test/src/main/java/org/igniterealtime/smack/inttest/debugger/StandardSinttestDebugger.java +++ b/smack-integration-test/src/main/java/org/igniterealtime/smack/inttest/debugger/StandardSinttestDebugger.java @@ -16,13 +16,13 @@ */ package org.igniterealtime.smack.inttest.debugger; -import java.io.File; import java.io.IOException; import java.io.Writer; import java.lang.reflect.Constructor; import java.lang.reflect.Method; import java.nio.file.Files; import java.nio.file.Path; +import java.nio.file.Paths; import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; import java.util.logging.Level; @@ -61,12 +61,11 @@ public StandardSinttestDebugger(ZonedDateTime restRunStart, String testRunId, St // We don't want to fill up the memory. tmpdir = "/var/tmp"; } - String basePath = tmpdir - + File.separator - + "sinttest-" + System.getProperty("user.name") - + File.separator - + DATE_TIME_FORMATTER.format(restRunStart) + "-" + testRunId - ; + Path basePath = Paths.get( + tmpdir, + "sinttest-" + System.getProperty("user.name"), + DATE_TIME_FORMATTER.format(restRunStart) + "-" + testRunId + ); boolean console = true; if (options != null) { @@ -98,7 +97,7 @@ public StandardSinttestDebugger(ZonedDateTime restRunStart, String testRunId, St basePath = null; break; default: - basePath = value; + basePath = Path.of(value); break; } break; @@ -109,7 +108,7 @@ public StandardSinttestDebugger(ZonedDateTime restRunStart, String testRunId, St } if (basePath != null) { - this.basePath = Path.of(basePath); + this.basePath = basePath; Path completeLogFile = this.basePath.resolve("completeLog"); Path outsideTestLogFile = this.basePath.resolve("outsideTestLog"); Path testsFile = this.basePath.resolve("tests"); From dea51d6a01add1445dd9077f6f55706dc73a9a5b Mon Sep 17 00:00:00 2001 From: Sergey Ponomarev Date: Fri, 10 Oct 2025 14:35:18 +0300 Subject: [PATCH 2/2] FormFieldRegistry: loadFormFieldRegistryEntries(): use try with close --- .../smackx/formtypes/FormFieldRegistry.java | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/formtypes/FormFieldRegistry.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/formtypes/FormFieldRegistry.java index c22555c0e2..70240a194b 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/formtypes/FormFieldRegistry.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/formtypes/FormFieldRegistry.java @@ -104,6 +104,7 @@ private static void loadFormFieldRegistryEntry(InputStream inputStream, String s } } } + private static void loadFormFieldRegistryEntries() throws IOException, IllegalStateException, XmlPullParserException, URISyntaxException { var url = XDataManager.class.getProtectionDomain().getCodeSource().getLocation(); if (url == null) throw new IllegalStateException(); @@ -118,11 +119,8 @@ private static void loadFormFieldRegistryEntries() throws IOException, IllegalSt .filter(f -> f.toString().startsWith(prefix)) .collect(Collectors.toList()); for (var file : files) { - var inputStream = Files.newInputStream(file); - try { + try (var inputStream = Files.newInputStream(file)) { loadFormFieldRegistryEntry(inputStream, file.toString()); - } finally { - inputStream.close(); } } } @@ -136,11 +134,8 @@ private static void loadFormFieldRegistryEntries() throws IOException, IllegalSt .filter(e -> e.getName().startsWith("org.igniterealtime.smack/xdata/form-registry/")) .collect(Collectors.toList()); for (var file : files) { - var inputStream = jar.getInputStream(file); - try { + try (var inputStream = jar.getInputStream(file)) { loadFormFieldRegistryEntry(inputStream, file.toString()); - } finally { - inputStream.close(); } } }