Bug 1502741 - Suppress StrictMode warning for Robocop logging. r=gbrown

The PrintWriter might start the write only when it is being closed (which
flushes all pending changes to disk), which means that we need an outer try
statement in order to reliably suppress the corresponding StrictMode warnings.

Differential Revision: https://phabricator.services.mozilla.com/D10012

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Jan Henning 2018-10-29 18:42:26 +00:00
Родитель ee3a7d1927
Коммит f4b3204922
1 изменённых файлов: 17 добавлений и 13 удалений

Просмотреть файл

@ -26,6 +26,7 @@ import org.mozilla.gecko.gfx.PanningPerfAPI;
import org.mozilla.gecko.util.BundleEventListener;
import org.mozilla.gecko.util.EventCallback;
import org.mozilla.gecko.util.GeckoBundle;
import org.mozilla.gecko.util.StrictModeContext;
import org.mozilla.geckoview.GeckoView;
import android.app.Activity;
@ -447,6 +448,7 @@ public class FennecNativeDriver implements Driver, CompositorController.GetPixel
log(level, null, t);
}
@SuppressWarnings("try")
public static void log(LogLevel level, String message, Throwable t) {
if (mLogFile == null) {
throw new RuntimeException(
@ -456,19 +458,21 @@ public class FennecNativeDriver implements Driver, CompositorController.GetPixel
if (level.isEnabled(mLogLevel)) {
PrintWriter pw = null;
try {
pw = new PrintWriter(new FileWriter(mLogFile, true));
if (message != null) {
pw.println(message);
}
if (t != null) {
t.printStackTrace(pw);
}
} catch (IOException ioe) {
Log.e("Robocop", "exception with file writer on: " + mLogFile);
} finally {
if (pw != null) {
pw.close();
try (StrictModeContext unused = StrictModeContext.allowDiskWrites()) {
try {
pw = new PrintWriter(new FileWriter(mLogFile, true));
if (message != null) {
pw.println(message);
}
if (t != null) {
t.printStackTrace(pw);
}
} catch (IOException ioe) {
Log.e("Robocop", "exception with file writer on: " + mLogFile);
} finally {
if (pw != null) {
pw.close();
}
}
}