Fix two strict mode warnings.

Bug: 9052555
Change-Id: I86e90488679a78a9f6e901b640025619293765a0
main
Jean Chalard 2013-05-30 18:53:56 +09:00
parent 8eb214d7e1
commit e90d039e0c
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);
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.
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());
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.
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
*