Skip to content

Commit 61ca71c

Browse files
committed
Use Paths.get() to avoid concatenation with File.separator
loadFormFieldRegistryEntries(): use try with close
1 parent fd2da27 commit 61ca71c

File tree

3 files changed

+12
-22
lines changed

3 files changed

+12
-22
lines changed

smack-core/src/main/java/org/jivesoftware/smack/util/TLSUtils.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.io.FileNotFoundException;
2323
import java.io.IOException;
2424
import java.io.InputStream;
25+
import java.nio.file.Paths;
2526
import java.security.MessageDigest;
2627
import java.security.NoSuchAlgorithmException;
2728
import java.security.cert.Certificate;
@@ -217,8 +218,8 @@ public X509Certificate[] getAcceptedIssuers() {
217218

218219
static {
219220
String javaHome = System.getProperty("java.home");
220-
String defaultTruststorePath = javaHome + File.separator + "lib" + File.separator + "security" + File.separator + "cacerts";
221-
DEFAULT_TRUSTSTORE_PATH = new File(defaultTruststorePath);
221+
var defaultTruststorePath = Paths.get(javaHome, "lib", "security", "cacerts");
222+
DEFAULT_TRUSTSTORE_PATH = defaultTruststorePath.toFile();
222223
}
223224

224225
public static FileInputStream getDefaultTruststoreStreamIfPossible() {

smack-extensions/src/main/java/org/jivesoftware/smackx/formtypes/FormFieldRegistry.java

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
*/
1717
package org.jivesoftware.smackx.formtypes;
1818

19-
import java.io.File;
2019
import java.io.IOException;
2120
import java.io.InputStream;
2221
import java.net.URISyntaxException;
@@ -105,26 +104,23 @@ private static void loadFormFieldRegistryEntry(InputStream inputStream, String s
105104
}
106105
}
107106
}
107+
108108
private static void loadFormFieldRegistryEntries() throws IOException, IllegalStateException, XmlPullParserException, URISyntaxException {
109109
var url = XDataManager.class.getProtectionDomain().getCodeSource().getLocation();
110110
if (url == null) throw new IllegalStateException();
111111

112112
if (url.getProtocol().equals("file") && !url.getPath().endsWith(".jar")) {
113113
var path = Paths.get(url.toURI());
114114
if (!Files.isDirectory(path)) throw new IllegalStateException("Code source location " + url + " is not a directory");
115-
var prefix = path.toString() + File.separator + "org.igniterealtime.smack" + File.separator + "xdata"
116-
+ File.separator + "form-registry" + File.separator;
115+
var prefix = Paths.get(path.toString(), "org.igniterealtime.smack", "xdata", "form-registry").toString();
117116

118117
try (var walk = Files.walk(path)) {
119118
var files = walk.filter(Files::isRegularFile)
120119
.filter(f -> f.toString().startsWith(prefix))
121120
.collect(Collectors.toList());
122121
for (var file : files) {
123-
var inputStream = Files.newInputStream(file);
124-
try {
122+
try (var inputStream = Files.newInputStream(file)) {
125123
loadFormFieldRegistryEntry(inputStream, file.toString());
126-
} finally {
127-
inputStream.close();
128124
}
129125
}
130126
}
@@ -138,11 +134,8 @@ private static void loadFormFieldRegistryEntries() throws IOException, IllegalSt
138134
.filter(e -> e.getName().startsWith("org.igniterealtime.smack/xdata/form-registry/"))
139135
.collect(Collectors.toList());
140136
for (var file : files) {
141-
var inputStream = jar.getInputStream(file);
142-
try {
137+
try (var inputStream = jar.getInputStream(file)) {
143138
loadFormFieldRegistryEntry(inputStream, file.toString());
144-
} finally {
145-
inputStream.close();
146139
}
147140
}
148141
}

smack-integration-test/src/main/java/org/igniterealtime/smack/inttest/debugger/StandardSinttestDebugger.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@
1616
*/
1717
package org.igniterealtime.smack.inttest.debugger;
1818

19-
import java.io.File;
2019
import java.io.IOException;
2120
import java.io.Writer;
2221
import java.lang.reflect.Constructor;
2322
import java.lang.reflect.Method;
2423
import java.nio.file.Files;
2524
import java.nio.file.Path;
25+
import java.nio.file.Paths;
2626
import java.time.ZonedDateTime;
2727
import java.time.format.DateTimeFormatter;
2828
import java.util.logging.Level;
@@ -61,12 +61,8 @@ public StandardSinttestDebugger(ZonedDateTime restRunStart, String testRunId, St
6161
// We don't want to fill up the memory.
6262
tmpdir = "/var/tmp";
6363
}
64-
String basePath = tmpdir
65-
+ File.separator
66-
+ "sinttest-" + System.getProperty("user.name")
67-
+ File.separator
68-
+ DATE_TIME_FORMATTER.format(restRunStart) + "-" + testRunId
69-
;
64+
Path basePath = Paths.get(tmpdir, "sinttest-" + System.getProperty("user.name"),
65+
DATE_TIME_FORMATTER.format(restRunStart) + "-" + testRunId);
7066
boolean console = true;
7167

7268
if (options != null) {
@@ -98,7 +94,7 @@ public StandardSinttestDebugger(ZonedDateTime restRunStart, String testRunId, St
9894
basePath = null;
9995
break;
10096
default:
101-
basePath = value;
97+
basePath = Path.of(value);
10298
break;
10399
}
104100
break;
@@ -109,7 +105,7 @@ public StandardSinttestDebugger(ZonedDateTime restRunStart, String testRunId, St
109105
}
110106

111107
if (basePath != null) {
112-
this.basePath = Path.of(basePath);
108+
this.basePath = basePath;
113109
Path completeLogFile = this.basePath.resolve("completeLog");
114110
Path outsideTestLogFile = this.basePath.resolve("outsideTestLog");
115111
Path testsFile = this.basePath.resolve("tests");

0 commit comments

Comments
 (0)