Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue Jenkins-36718 - Fix DM_DEFAULT_ENCODING scanned by spotbugs #9784

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
4 changes: 2 additions & 2 deletions core/src/main/java/hudson/console/ConsoleNote.java
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@
* encoding is ASCII compatible.
*/
public void encodeTo(Writer out) throws IOException {
out.write(encodeToBytes().toString());
out.write(encodeToBytes().toString(StandardCharsets.UTF_8));

Check warning on line 197 in core/src/main/java/hudson/console/ConsoleNote.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 197 is not covered by tests
}

private ByteArrayOutputStream encodeToBytes() throws IOException {
Expand Down Expand Up @@ -224,7 +224,7 @@
* Works like {@link #encodeTo(Writer)} but obtain the result as a string.
*/
public String encode() throws IOException {
return encodeToBytes().toString();
return encodeToBytes().toString(StandardCharsets.UTF_8);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import java.io.Writer;
import java.net.URL;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.StandardOpenOption;
import java.util.logging.Level;
Expand Down Expand Up @@ -145,7 +146,7 @@
int r = new LocalLauncher(task).launch().cmds(executable, "restart!")
.stdout(task).pwd(home).join();
if (r != 0)
throw new IOException(baos.toString());
throw new IOException(baos.toString(StandardCharsets.UTF_8));

Check warning on line 149 in core/src/main/java/hudson/lifecycle/WindowsServiceLifecycle.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 149 is not covered by tests
}

private static File getBaseDir() {
Expand Down
3 changes: 1 addition & 2 deletions core/src/main/java/hudson/util/TextFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import hudson.Util;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.RandomAccessFile;
Expand Down Expand Up @@ -114,7 +113,7 @@ public void write(String text) throws IOException {
public @NonNull String head(int numChars) throws IOException {
char[] buf = new char[numChars];
int read = 0;
try (Reader r = new FileReader(file)) {
try (Reader r = Files.newBufferedReader(file.toPath(), StandardCharsets.UTF_8)) {
while (read < numChars) {
int d = r.read(buf, read, buf.length - read);
if (d < 0)
Expand Down
10 changes: 0 additions & 10 deletions core/src/spotbugs/excludesFilter.xml
Original file line number Diff line number Diff line change
Expand Up @@ -180,16 +180,6 @@
this section.
- If it is not a false positive, fix the bug, then remove the exclusion from this section.
-->
<Match>
<And>
<Bug pattern="DM_DEFAULT_ENCODING"/>
<Or>
<Class name="hudson.console.ConsoleNote"/>
<Class name="hudson.lifecycle.WindowsServiceLifecycle"/>
<Class name="hudson.util.TextFile"/>
</Or>
</And>
</Match>
<Match>
<Confidence value="2"/>
<Or>
Expand Down
Loading