-
-
Notifications
You must be signed in to change notification settings - Fork 8.9k
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
Fix more DM_DEFAULT_ENCODING
SpotBugs violations
#6098
Changes from 6 commits
98b0a3e
72d1a11
3f8783c
30658ee
56ca70e
28dcba1
106ace3
98fb885
758af4d
7dca57c
8211d01
b30b7ac
907a10f
797076f
72353c8
febd273
b8d3f88
fcf6413
f6553b5
b1d9436
e4b4978
1507bac
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,9 +32,12 @@ | |
import hudson.util.StreamTaskListener; | ||
import hudson.util.jna.Kernel32; | ||
import java.io.File; | ||
import java.io.FileWriter; | ||
import java.io.IOException; | ||
import java.io.Writer; | ||
import java.net.URL; | ||
import java.nio.charset.Charset; | ||
import java.nio.file.Files; | ||
import java.nio.file.StandardOpenOption; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
import jenkins.model.Jenkins; | ||
|
@@ -109,7 +112,7 @@ public void rewriteHudsonWar(File by) throws IOException { | |
File baseDir = getBaseDir(); | ||
File copyFiles = new File(baseDir,baseName+".copies"); | ||
|
||
try (FileWriter w = new FileWriter(copyFiles, true)) { | ||
try (Writer w = Files.newBufferedWriter(Util.fileToPath(copyFiles), Charset.defaultCharset(), StandardOpenOption.CREATE, StandardOpenOption.APPEND)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A Windows-specific file, so we cannot assume UTF-8. |
||
w.write(by.getAbsolutePath() + '>' + getHudsonWar().getAbsolutePath() + '\n'); | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -27,7 +27,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; | ||||||||||||||||||||||
|
@@ -113,7 +112,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(Util.fileToPath(file), Charset.defaultCharset())) { | ||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does not match jenkins/core/src/main/java/hudson/util/TextFile.java Lines 66 to 69 in 28dcba1
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But it does match jenkins/core/src/main/java/hudson/util/TextFile.java Lines 176 to 181 in 75ce81d
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These are secondary methods. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. commit 14d980c FTR There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Pre-existing issue, but never mind that. Done. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually I am not comfortable taking on this risk changing the behavior of an existing public API. Reverted. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Then at least leave comments noting that the behavior of methods in this class is inconsistent. Not even sure if these non- There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Opted for a more conservative approach of deprecating the methods that use the default charset in favor of non-deprecated versions that take an explicit charset. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
as does Thus forcing users to specify a charset for Besides that - this code is wrong as it is ignoring the passed in there only seems to be a couple of usages of
|
||||||||||||||||||||||
while (read<numChars) { | ||||||||||||||||||||||
int d = r.read(buf,read,buf.length-read); | ||||||||||||||||||||||
if (d<0) | ||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -16,10 +16,12 @@ | |||||||||||
import hudson.slaves.SlaveComputer; | ||||||||||||
import java.io.IOException; | ||||||||||||
import java.io.OutputStream; | ||||||||||||
import java.io.OutputStreamWriter; | ||||||||||||
import java.io.PrintWriter; | ||||||||||||
import java.lang.reflect.InvocationTargetException; | ||||||||||||
import java.lang.reflect.Method; | ||||||||||||
import java.nio.channels.ClosedChannelException; | ||||||||||||
import java.nio.charset.Charset; | ||||||||||||
import java.nio.charset.StandardCharsets; | ||||||||||||
import java.security.MessageDigest; | ||||||||||||
import java.util.concurrent.ExecutionException; | ||||||||||||
|
@@ -152,7 +154,7 @@ public void beforeChannel(@NonNull JnlpConnectionState event) { | |||||||||||
final SlaveComputer computer = state.getNode(); | ||||||||||||
final OutputStream log = computer.openLogFile(); | ||||||||||||
state.setLog(log); | ||||||||||||
try (PrintWriter logw = new PrintWriter(log, true)) { | ||||||||||||
try (PrintWriter logw = new PrintWriter(new OutputStreamWriter(log, Charset.defaultCharset()), true)) { | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agent log files should be in UTF-8. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here and elsewhere, please provide reasoning when you make requests of me. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any plugin can write text to these logs, and it is intended solely for use by Jenkins, so there is no reason to allow non-UTF-8 encoding. Looks like some other places need to be fixed; at least:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A bigger change than what I am trying to achieve in this PR. For now I have added a comment matching
|
||||||||||||
logw.println("Inbound agent connected from " + event.getRemoteEndpointDescription()); | ||||||||||||
} | ||||||||||||
for (ChannelConfigurator cc : ChannelConfigurator.all()) { | ||||||||||||
|
@@ -172,7 +174,7 @@ public void afterChannel(@NonNull JnlpConnectionState event) { | |||||||||||
try { | ||||||||||||
computer.setChannel(event.getChannel(), state.getLog(), null); | ||||||||||||
} catch (IOException | InterruptedException e) { | ||||||||||||
PrintWriter logw = new PrintWriter(state.getLog(), true); | ||||||||||||
PrintWriter logw = new PrintWriter(new OutputStreamWriter(state.getLog(), Charset.defaultCharset()), true); | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto |
||||||||||||
Functions.printStackTrace(e, logw); | ||||||||||||
try { | ||||||||||||
event.getChannel().close(); | ||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a few lines above, the Javadoc states (emphasis mine):