FileNotFoundexception on migration files
biafra23 opened this issue · 7 comments
This can be reproduced with the demo-simple only on Marshmallow:
Create 1040 migration files with size 0 bytes and start the app. Depending whether debuggable is switched on the app will crash at file 553 or 1039. In real world apps this Exception is thrown after 6 files.
Looking at the source it seems there is a reader.close()
missing in finally. But even adding that does not prevent the Exception from being thrown. The problem only occurs on clean install.
java.io.FileNotFoundException: migrations/553_DEPRECATED.SQL
at android.content.res.AssetManager.openAsset(Native Method)
at android.content.res.AssetManager.open(AssetManager.java:313)
at novoda.lib.sqliteprovider.migration.Migrations.migrate(Migrations.java:91)
at novoda.lib.sqliteprovider.sqlite.ExtendedSQLiteOpenHelper.onCreate(ExtendedSQLiteOpenHelper.java:76)
at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:251)
at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:163)
at novoda.lib.sqliteprovider.provider.SQLiteContentProvider.insert(SQLiteContentProvider.java:94)
at android.content.ContentProvider$Transport.insert(ContentProvider.java:263)
at android.content.ContentResolver.insert(ContentResolver.java:1231)
at com.novoda.sqliteprovider.demo.simple.ui.MainFragment.saveNewShopToDatabase(MainFragment.java:44)
at com.novoda.sqliteprovider.demo.simple.ui.MainFragment.onCreate(MainFragment.java:32)
at android.support.v4.app.Fragment.performCreate(Fragment.java:1766)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:917)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1116)
at android.support.v4.app.FragmentManagerImpl.addFragment(FragmentManager.java:1218)
at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2170)
at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:300)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:748)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:393)
at android.app.Activity.setContentView(Activity.java:2166)
at com.novoda.sqliteprovider.demo.simple.ui.MainActivity.onCreate(MainActivity.java:13)
nice find 👍
Here is a short shell script to create the necessary SQL files:
for (( i=1; i<=1999; i++ )) ; do touch ${i}_DEPRECATED.SQL; done
Works with zsh. Not sure about bash
is this fixed now?
I can still see it on a device and an emulator (API 25). Looks like a problem with the native implemention (mmap).
12-01 13:31:43.827 32436-32436/com.novoda.sqliteprovider.demo.simple E/filemap: mmap(1159168,0) failed: Invalid argument
12-01 13:31:43.827 32436-32436/com.novoda.sqliteprovider.demo.simple W/asset: create map from entry failed
12-01 13:31:43.852 32436-32436/com.novoda.sqliteprovider.demo.simple E/SQLiteProvider-Mig: FileNotFoundException
java.io.FileNotFoundException: migrations/1311_DEPRECATED.SQL
at android.content.res.AssetManager.openAsset(Native Method)
at android.content.res.AssetManager.open(AssetManager.java:331)
at novoda.lib.sqliteprovider.migration.Migrations.migrate(Migrations.java:86)
The question is whether the InsertHelper should throw an exception at
or the open helper at
I would say this works as intended (as the lib only logs errors). If the migration fails, the user of the library has to take care of errors. Maybe the readme should be updated.
Closing as this repository is no longer under maintenance and it's about to be archived