Skip to content

Commit

Permalink
Fix spotbugs warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
nikita-tkachenko-datadog committed Sep 23, 2024
1 parent fab4a0b commit e56ff06
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.logging.Level;
Expand Down Expand Up @@ -99,7 +100,7 @@ private void writeDiagnosticFlare(OutputStream out) throws IOException {

zipOut.closeEntry();
zipOut.putNextEntry(new ZipEntry(contributor.getFilename() + ".error"));
zipOut.write(ExceptionUtils.getStackTrace(e).getBytes());
zipOut.write(ExceptionUtils.getStackTrace(e).getBytes(StandardCharsets.UTF_8));
} finally {
zipOut.closeEntry();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import org.apache.commons.lang3.tuple.Pair;
import org.datadog.jenkins.plugins.datadog.DatadogUtilities;

import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
Expand All @@ -16,8 +16,6 @@
@Extension
public class ExceptionsFlare implements FlareContributor {

public static final DateFormat DATE_FORMATTER = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS Z");

@Override
public String getFilename() {
return "exceptions.txt";
Expand All @@ -27,13 +25,14 @@ public String getFilename() {
public void writeFileContents(OutputStream out) {
// Print writer is not closed intentionally, to avoid closing out.
// Auto-flush set to true ensures everything is witten
PrintWriter printWriter = new PrintWriter(out, true);
PrintWriter printWriter = new PrintWriter(out, true, StandardCharsets.UTF_8);

DateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS Z");
BlockingQueue<Pair<Date, Throwable>> exceptionsBuffer = DatadogUtilities.getExceptionsBuffer();
for (Pair<Date, Throwable> p : exceptionsBuffer) {
Date date = p.getKey();
Throwable exception = p.getValue();
printWriter.println(DATE_FORMATTER.format(date) + ": " + ExceptionUtils.getStackTrace(exception));
printWriter.println(dateFormatter.format(date) + ": " + ExceptionUtils.getStackTrace(exception));
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.datadog.jenkins.plugins.datadog.flare;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public interface FlareContributor {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import java.io.OutputStream;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.ListIterator;
import java.util.logging.Formatter;
Expand All @@ -31,7 +32,7 @@ public String getFilename() {
public void writeFileContents(OutputStream out) {
// Print writer is not closed intentionally, to avoid closing out.
// Auto-flush set to true ensures everything is witten
PrintWriter printWriter = new PrintWriter(out, true);
PrintWriter printWriter = new PrintWriter(out, true, StandardCharsets.UTF_8);

List<LogRecord> logRecords = Jenkins.logRecords;
ListIterator<LogRecord> it = logRecords.listIterator(logRecords.size());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import java.io.OutputStream;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.List;
import java.util.ListIterator;
Expand Down Expand Up @@ -62,7 +63,7 @@ public String getFilename() {
public void writeFileContents(OutputStream out) {
// Print writer is not closed intentionally, to avoid closing out.
// Auto-flush set to true ensures everything is witten
PrintWriter printWriter = new PrintWriter(out, true);
PrintWriter printWriter = new PrintWriter(out, true, StandardCharsets.UTF_8);

Jenkins jenkins = Jenkins.get();
LogRecorderManager logRecorderManager = jenkins.getLog();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public void writeFileContents(OutputStream out) throws IOException {
payload.put("os-architecture", System.getProperty("os.arch"));
payload.put("os-name", System.getProperty("os.name"));
payload.put("os-version", System.getProperty("os.version"));
payload.put("jenkins-version", Jenkins.getVersion().toString());
payload.put("jenkins-version", String.valueOf(Jenkins.getVersion()));
payload.put("plugin-version", DatadogUtilities.getDatadogPluginVersion());

String payloadString = payload.toString(2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import hudson.Extension;

import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;
import java.util.Map;

@Extension
Expand All @@ -19,7 +19,7 @@ public String getFilename() {
public void writeFileContents(OutputStream out) {
// Print writer is not closed intentionally, to avoid closing out.
// Auto-flush set to true ensures everything is witten
PrintWriter printWriter = new PrintWriter(out, true);
PrintWriter printWriter = new PrintWriter(out, true, StandardCharsets.UTF_8);

Map<Thread, StackTraceElement[]> allStackTraces = Thread.getAllStackTraces();
for (Map.Entry<Thread, StackTraceElement[]> entry : allStackTraces.entrySet()) {
Expand Down

0 comments on commit e56ff06

Please sign in to comment.