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 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 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(new String(encodeToBytes().toByteArray(), 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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@programbeginnerTW Could you please check this warning message, please?

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

}

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

/**
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(new String(baos.toByteArray(), 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
Loading