Merge "Fix two strict mode warnings."

This commit is contained in:
Jean Chalard 2013-05-30 11:16:09 +00:00 committed by Android (Google) Code Review
commit faa7fbfaa2
2 changed files with 42 additions and 25 deletions

View file

@ -572,7 +572,8 @@ public class MetadataDbHelper extends SQLiteOpenHelper {
* If several clients use the same metadata URL, we know to only download it once, and
* dispatch the update process across all relevant clients when the download ends. This means
* several clients may share a single download ID if they share a metadata URI.
* The dispatching is done in {@link UpdateHandler#downloadFinished(Context, Intent)}, which
* The dispatching is done in
* {@link UpdateHandler#downloadFinished(Context, android.content.Intent)}, which
* finds out about the list of relevant clients by calling this method.
*
* @param context a context instance to open the databases
@ -863,17 +864,20 @@ public class MetadataDbHelper extends SQLiteOpenHelper {
r.getAsString(WORDLISTID_COLUMN),
Integer.toString(STATUS_INSTALLED) },
null, null, null);
try {
if (c.moveToFirst()) {
// There should never be more than one file, but if there are, it's a bug
// and we should remove them all. I think it might happen if the power of the
// phone is suddenly cut during an update.
// and we should remove them all. I think it might happen if the power of
// the phone is suddenly cut during an update.
final int filenameIndex = c.getColumnIndex(LOCAL_FILENAME_COLUMN);
do {
Utils.l("Setting for removal", c.getString(filenameIndex));
filenames.add(c.getString(filenameIndex));
} while (c.moveToNext());
}
} finally {
c.close();
}
r.put(STATUS_COLUMN, STATUS_INSTALLED);
db.beginTransactionNonExclusive();
// Delete all old entries. There should never be any stalled entries, but if

View file

@ -32,6 +32,7 @@ import com.android.inputmethod.latin.DictionaryInfoUtils.DictionaryInfo;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.Closeable;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
@ -319,20 +320,12 @@ public final class BinaryDictionaryFileDumper {
// Try the next method.
} finally {
// Ignore exceptions while closing files.
try {
if (null != afd) afd.close();
if (null != inputStream) inputStream.close();
if (null != uncompressedStream) uncompressedStream.close();
if (null != decryptedStream) decryptedStream.close();
if (null != bufferedInputStream) bufferedInputStream.close();
} catch (Exception e) {
Log.e(TAG, "Exception while closing a file descriptor", e);
}
try {
if (null != bufferedOutputStream) bufferedOutputStream.close();
} catch (Exception e) {
Log.e(TAG, "Exception while closing a file", e);
}
closeAssetFileDescriptorAndReportAnyException(afd);
closeCloseableAndReportAnyException(inputStream);
closeCloseableAndReportAnyException(uncompressedStream);
closeCloseableAndReportAnyException(decryptedStream);
closeCloseableAndReportAnyException(bufferedInputStream);
closeCloseableAndReportAnyException(bufferedOutputStream);
}
}
@ -352,6 +345,26 @@ public final class BinaryDictionaryFileDumper {
}
}
// Ideally the two following methods should be merged, but AssetFileDescriptor does not
// implement Closeable although it does implement #close(), and Java does not have
// structural typing.
private static void closeAssetFileDescriptorAndReportAnyException(
final AssetFileDescriptor file) {
try {
if (null != file) file.close();
} catch (Exception e) {
Log.e(TAG, "Exception while closing a file", e);
}
}
private static void closeCloseableAndReportAnyException(final Closeable file) {
try {
if (null != file) file.close();
} catch (Exception e) {
Log.e(TAG, "Exception while closing a file", e);
}
}
/**
* Queries a content provider for word list data for some locale and cache the returned files
*