Android源码中的低级错误
我这里要说的是MediaScanner.java,代码连接http://android.git.kernel.org/?p=platform/frameworks/base.git;a=blob_plain;f=media/java/android/media/MediaScanner.java;hb=HEAD
请看pruneDeadThumbnailFiles()这个函数
Cursor c = mMediaProvider.query( mThumbsUri, new String [] { "_data" }, null, null, null); Log.v(TAG, "pruneDeadThumbnailFiles... " + c); if (c != null && c.moveToFirst()) { do { String fullPathString = c.getString(0); existingFiles.remove(fullPathString); } while (c.moveToNext()); } for (String fileToDelete : existingFiles) { if (Config.LOGV) Log.v(TAG, "fileToDelete is " + fileToDelete); try { (new File(fileToDelete)).delete(); } catch (SecurityException ex) { } } Log.v(TAG, "/pruneDeadThumbnailFiles... " + c); if (c != null) { c.close(); }?难道写这个函数的工程师不知道要把数据库游标的关闭放在finally里面吗?导致了这样的问题:
01-06 00:19:22.949: ERROR/StrictMode(514): Releasing statement in a finalizer. Please ensure that you explicitly call close() on your cursor: SELECT _id, date_modified, _data FROM video WHERE (mime_type != 'video/avi' AND mime_type != 'video01-06 00:19:22.949: ERROR/StrictMode(514): android.database.sqlite.DatabaseObjectNotClosedException: Application did not close the cursor or database object that was opened here01-06 00:19:22.949: ERROR/StrictMode(514): at android.database.sqlite.SQLiteCompiledSql.<init>(SQLiteCompiledSql.java:63)01-06 00:19:22.949: ERROR/StrictMode(514): at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:83)01-06 00:19:22.949: ERROR/StrictMode(514): at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:49)01-06 00:19:22.949: ERROR/StrictMode(514): at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:42)01-06 00:19:22.949: ERROR/StrictMode(514): at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1356)01-06 00:19:22.949: ERROR/StrictMode(514): at android.database.sqlite.SQLiteQueryBuilder.query(SQLiteQueryBuilder.java:330)01-06 00:19:22.949: ERROR/StrictMode(514): at com.android.providers.media.MediaProvider.query(MediaProvider.java:1607)01-06 00:19:22.949: ERROR/StrictMode(514): at android.content.ContentProvider$Transport.bulkQuery(ContentProvider.java:174)01-06 00:19:22.949: ERROR/StrictMode(514): at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:111)01-06 00:19:22.949: ERROR/StrictMode(514): at android.os.Binder.execTransact(Binder.java:320)01-06 00:19:22.949: ERROR/StrictMode(514): at dalvik.system.NativeStart.run(Native Method)?