Merge "Fix JsonWriter bug"

main
Kurt Partridge 2013-04-17 18:20:34 +00:00 committed by Android (Google) Code Review
commit 1f99e04bba
1 changed files with 13 additions and 3 deletions

View File

@ -108,10 +108,14 @@ public class ResearchLog {
@Override @Override
public Object call() throws Exception { public Object call() throws Exception {
try { try {
if (mHasWrittenData) { // TODO: This is necessary to avoid an exception. Better would be to not even
// open the JsonWriter if the file is not even opened unless there is valid data
// to write.
if (!mHasWrittenData) {
mJsonWriter.beginArray();
}
mJsonWriter.endArray(); mJsonWriter.endArray();
mHasWrittenData = false; mHasWrittenData = false;
}
mJsonWriter.flush(); mJsonWriter.flush();
mJsonWriter.close(); mJsonWriter.close();
if (DEBUG) { if (DEBUG) {
@ -159,6 +163,12 @@ public class ResearchLog {
public Object call() throws Exception { public Object call() throws Exception {
try { try {
if (mHasWrittenData) { if (mHasWrittenData) {
// TODO: This is necessary to avoid an exception. Better would be to not
// even open the JsonWriter if the file is not even opened unless there is
// valid data to write.
if (!mHasWrittenData) {
mJsonWriter.beginArray();
}
mJsonWriter.endArray(); mJsonWriter.endArray();
mJsonWriter.close(); mJsonWriter.close();
mHasWrittenData = false; mHasWrittenData = false;