From d1f6d1ab58e82c7854cb569554f7626be10f7baf Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sat, 10 Nov 2018 16:10:57 +1300 Subject: Fix some FindBugs issues --- src/org/traccar/helper/Log.java | 15 ++++++++++----- src/org/traccar/sms/HttpSmsClient.java | 3 ++- 2 files changed, 12 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/org/traccar/helper/Log.java b/src/org/traccar/helper/Log.java index a26da6b30..9519a33f1 100644 --- a/src/org/traccar/helper/Log.java +++ b/src/org/traccar/helper/Log.java @@ -19,11 +19,13 @@ import org.traccar.Config; import java.io.BufferedWriter; import java.io.File; -import java.io.FileWriter; +import java.io.FileOutputStream; import java.io.IOException; +import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.io.StringWriter; import java.io.Writer; +import java.nio.charset.StandardCharsets; import java.text.SimpleDateFormat; import java.util.Date; import java.util.logging.ConsoleHandler; @@ -59,11 +61,14 @@ public final class Log { if (writer != null && !suffix.equals(this.suffix)) { writer.close(); writer = null; - new File(name).renameTo(new File(name + "." + this.suffix)); + if (!new File(name).renameTo(new File(name + "." + this.suffix))) { + throw new RuntimeException("Log file renaiming failed"); + } } if (writer == null) { this.suffix = suffix; - writer = new BufferedWriter(new FileWriter(name, true)); + writer = new BufferedWriter( + new OutputStreamWriter(new FileOutputStream(name, true), StandardCharsets.UTF_8)); } writer.write(getFormatter().format(record)); writer.flush(); @@ -74,7 +79,7 @@ public final class Log { } @Override - public void flush() { + public synchronized void flush() { if (writer != null) { try { writer.flush(); @@ -85,7 +90,7 @@ public final class Log { } @Override - public void close() throws SecurityException { + public synchronized void close() throws SecurityException { if (writer != null) { try { writer.close(); diff --git a/src/org/traccar/sms/HttpSmsClient.java b/src/org/traccar/sms/HttpSmsClient.java index 3f7bc3c85..994e2db4e 100644 --- a/src/org/traccar/sms/HttpSmsClient.java +++ b/src/org/traccar/sms/HttpSmsClient.java @@ -49,7 +49,8 @@ public class HttpSmsClient implements SmsManager { if (authorization == null) { String user = Context.getConfig().getString("sms.http.user"); String password = Context.getConfig().getString("sms.http.password"); - authorization = "Basic " + DataConverter.printBase64((user + ":" + password).getBytes()); + authorization = "Basic " + + DataConverter.printBase64((user + ":" + password).getBytes(StandardCharsets.UTF_8)); } template = Context.getConfig().getString("sms.http.template").trim(); if (template.charAt(0) == '{' || template.charAt(0) == '[') { -- cgit v1.2.3