Skip to content

Commit 162c4c9

Browse files
author
Vincent Potucek
committed
[openrewrite] add JavaSecurityBestPractices
1 parent 20c5d95 commit 162c4c9

File tree

27 files changed

+40
-35
lines changed

27 files changed

+40
-35
lines changed

lib-extra/src/main/java/com/diffplug/spotless/extra/GitRatchet.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020-2025 DiffPlug
2+
* Copyright 2020-2023 DiffPlug
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

lib-extra/src/main/java/com/diffplug/spotless/extra/integration/DiffMessageFormatter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ public static Map.Entry<Integer, String> diff(Path rootDir, Formatter formatter,
251251
}
252252

253253
private static Map.Entry<Integer, String> diff(CleanProvider formatter, File file) throws IOException {
254-
String raw = Files.readString(file.toPath(), formatter.getEncoding());
254+
String raw = new String(Files.readAllBytes(file.toPath()), formatter.getEncoding());
255255
String rawUnix = LineEnding.toUnix(raw);
256256
String formatted = formatter.getFormatted(file, rawUnix);
257257
String formattedUnix = LineEnding.toUnix(formatted);

lib-extra/src/test/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStepTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2025 DiffPlug
2+
* Copyright 2016-2024 DiffPlug
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

lib-extra/src/test/java/com/diffplug/spotless/extra/wtp/EclipseWtpFormatterStepTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2025 DiffPlug
2+
* Copyright 2016-2024 DiffPlug
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

lib/src/main/java/com/diffplug/spotless/FormatterProperties.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public static FormatterProperties fromXmlContent(final Iterable<String> content)
114114

115115
public static FormatterProperties merge(Properties... properties) {
116116
FormatterProperties merged = new FormatterProperties();
117-
List.of(properties).forEach((source) -> merged.properties.putAll(source));
117+
List.of(properties).stream().forEach((source) -> merged.properties.putAll(source));
118118
return merged;
119119
}
120120

lib/src/main/java/com/diffplug/spotless/GitPrePushHookInstaller.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ private void doInstall() throws Exception {
172172
* such as file reading or writing errors
173173
*/
174174
private void uninstall(File gitHookFile) throws Exception {
175-
final var hook = Files.readString(gitHookFile.toPath());
175+
final var hook = Files.readString(gitHookFile.toPath(), UTF_8);
176176
final int hookStart = hook.indexOf(HOOK_HEADER);
177177
final int hookEnd = hook.indexOf(HOOK_FOOTER) + HOOK_FOOTER.length(); // hookEnd exclusive, so must be last symbol \n
178178

@@ -323,7 +323,7 @@ private boolean isGitInstalled() {
323323
* @throws Exception if an error occurs when reading the file.
324324
*/
325325
private boolean isGitHookInstalled(File gitHookFile) throws Exception {
326-
final var hook = Files.readString(gitHookFile.toPath());
326+
final var hook = Files.readString(gitHookFile.toPath(), UTF_8);
327327
return hook.contains(HOOK_HEADER) && hook.contains(HOOK_FOOTER);
328328
}
329329

lib/src/main/java/com/diffplug/spotless/generic/IdeaStep.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ private String format(IdeaStepFormatterCleanupResources ideaStepFormatterCleanup
224224
LOGGER.debug("command finished with exit code: {}", result.exitCode());
225225
LOGGER.debug("command finished with stdout: {}",
226226
result.assertExitZero(StandardCharsets.UTF_8));
227-
return Files.readString(tempFile.toPath());
227+
return Files.readString(tempFile.toPath(), StandardCharsets.UTF_8);
228228
} finally {
229229
Files.delete(tempFile.toPath());
230230
}

lib/src/main/java/com/diffplug/spotless/npm/NodeServerLayout.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public boolean isNodeModulesPrepared() {
9696
// check if it is NOT empty
9797
return ThrowingEx.get(() -> {
9898
try (Stream<Path> entries = Files.list(nodeModulesInstallDirPath)) {
99-
return entries.findAny().isPresent();
99+
return entries.findFirst().isPresent();
100100
}
101101
});
102102
}

lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2025 DiffPlug
2+
* Copyright 2016-2024 DiffPlug
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -137,7 +137,7 @@ private String assertFilepathInConfigOptions(File file) {
137137
return prettierConfigOptions;
138138
}
139139
// if the file has no name, we cannot use it
140-
if (file.getName().trim().isEmpty()) {
140+
if (file.getName().trim().length() == 0) {
141141
return prettierConfigOptions;
142142
}
143143
// if it is not there, we add it at the beginning of the Options

lib/src/main/java/com/diffplug/spotless/sql/dbeaver/FormatterToken.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2025 DiffPlug
2+
* Copyright 2016 DiffPlug
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

0 commit comments

Comments
 (0)