Cleanup in preparation for tests

multi-project commit with I1212da392ecda0ad78962da68941870b5a651eee

Change-Id: Ie74af59d4e45bf954723fee9dcf350a36468c381
diff --git a/java/src/com/android/inputmethod/research/LogStatement.java b/java/src/com/android/inputmethod/research/LogStatement.java
index 059146a..09b12fc 100644
--- a/java/src/com/android/inputmethod/research/LogStatement.java
+++ b/java/src/com/android/inputmethod/research/LogStatement.java
@@ -35,7 +35,7 @@
  * associated with the {@code String[] keys} are likely to reveal information about the user.  The
  * actual values are stored separately.
  */
-class LogStatement {
+public class LogStatement {
     private static final String TAG = LogStatement.class.getSimpleName();
     private static final boolean DEBUG = false && ProductionFlag.IS_EXPERIMENTAL_DEBUG;
 
@@ -166,6 +166,8 @@
     /**
      * Write the contents out through jsonWriter.
      *
+     * The JsonWriter class must have already had {@code JsonWriter.beginArray} called on it.
+     *
      * Note that this method is not thread safe for the same jsonWriter.  Callers must ensure
      * thread safety.
      */
diff --git a/java/src/com/android/inputmethod/research/LogUnit.java b/java/src/com/android/inputmethod/research/LogUnit.java
index a584a3a..1a9a720 100644
--- a/java/src/com/android/inputmethod/research/LogUnit.java
+++ b/java/src/com/android/inputmethod/research/LogUnit.java
@@ -110,7 +110,13 @@
     }
 
     /**
-     * Publish the contents of this LogUnit to researchLog.
+     * Publish the contents of this LogUnit to {@code researchLog}.
+     *
+     * For each publishable {@code LogStatement}, invoke {@link LogStatement#outputToLocked}.
+     *
+     * @param researchLog where to publish the contents of this {@code LogUnit}
+     * @param canIncludePrivateData whether the private data in this {@code LogUnit} should be
+     * included
      */
     public synchronized void publishTo(final ResearchLog researchLog,
             final boolean canIncludePrivateData) {
diff --git a/java/src/com/android/inputmethod/research/ResearchLog.java b/java/src/com/android/inputmethod/research/ResearchLog.java
index 24bf7d1..5114977 100644
--- a/java/src/com/android/inputmethod/research/ResearchLog.java
+++ b/java/src/com/android/inputmethod/research/ResearchLog.java
@@ -81,10 +81,7 @@
         }
     }
 
-    public ResearchLog(final File outputFile, Context context) {
-        if (outputFile == null) {
-            throw new IllegalArgumentException();
-        }
+    public ResearchLog(final File outputFile, final Context context) {
         mExecutor = Executors.newSingleThreadScheduledExecutor();
         mFile = outputFile;
         mContext = context;
@@ -112,7 +109,7 @@
                     Log.d(TAG, "error when closing ResearchLog:");
                     e.printStackTrace();
                 } finally {
-                    if (mFile.exists()) {
+                    if (mFile != null && mFile.exists()) {
                         mFile.setWritable(false, false);
                     }
                     if (onClosed != null) {
@@ -139,7 +136,9 @@
                         mHasWrittenData = false;
                     }
                 } finally {
-                    mIsAbortSuccessful = mFile.delete();
+                    if (mFile != null) {
+                        mIsAbortSuccessful = mFile.delete();
+                    }
                 }
                 return null;
             }
@@ -209,7 +208,7 @@
      */
     public JsonWriter getValidJsonWriterLocked() {
         try {
-            if (mJsonWriter == NULL_JSON_WRITER) {
+            if (mJsonWriter == NULL_JSON_WRITER && mFile != null) {
                 final FileOutputStream fos =
                         mContext.openFileOutput(mFile.getName(), Context.MODE_PRIVATE);
                 mJsonWriter = new JsonWriter(new BufferedWriter(new OutputStreamWriter(fos)));