Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add @After to guarantee DB was closed ? #511

Closed
sanao1006 opened this issue Mar 7, 2024 · 1 comment · Fixed by #512
Closed

Add @After to guarantee DB was closed ? #511

sanao1006 opened this issue Mar 7, 2024 · 1 comment · Fixed by #512

Comments

@sanao1006
Copy link
Contributor

Is your feature request related to a problem? Please describe.
When I run TimelineDaoTest on my local, I get the following warning message (the test passes)

System.logW: A resource was acquired at attached stack trace but never released. See java.io.Closeable for information on avoiding resource leaks.
java.lang.Throwable: Explicit termination method 'close' not called
	at dalvik.system.CloseGuard.$$robo$$dalvik_system_CloseGuard$openWithCallSite(CloseGuard.java:288)
	at dalvik.system.CloseGuard.openWithCallSite(CloseGuard.java)
	at dalvik.system.CloseGuard.$$robo$$dalvik_system_CloseGuard$open(CloseGuard.java:257)
	at jdk.internal.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at org.robolectric.shadows.ShadowCloseGuard$CloseGuardReflector$$Reflector14.open(Unknown Source)
	at org.robolectric.shadows.ShadowCloseGuard.open(ShadowCloseGuard.java:38)
	at dalvik.system.CloseGuard.open(CloseGuard.java)
	at android.database.sqlite.SQLiteDatabase.$$robo$$android_database_sqlite_SQLiteDatabase$openInner(SQLiteDatabase.java:1086)
	at android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java)
	at android.database.sqlite.SQLiteDatabase.$$robo$$android_database_sqlite_SQLiteDatabase$open(SQLiteDatabase.java:1065)
	at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java)
	at android.database.sqlite.SQLiteDatabase.$$robo$$android_database_sqlite_SQLiteDatabase$openDatabase(SQLiteDatabase.java:929)
	at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java)
	at android.database.sqlite.SQLiteDatabase.$$robo$$android_database_sqlite_SQLiteDatabase$createInMemory(SQLiteDatabase.java:1125)
	at android.database.sqlite.SQLiteDatabase.createInMemory(SQLiteDatabase.java)
	at android.database.sqlite.SQLiteOpenHelper.$$robo$$android_database_sqlite_SQLiteOpenHelper$getDatabaseLocked(SQLiteOpenHelper.java:368)
	at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java)
	at android.database.sqlite.SQLiteOpenHelper.$$robo$$android_database_sqlite_SQLiteOpenHelper$getWritableDatabase(SQLiteOpenHelper.java:316)
	at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java)
	at androidx.sqlite.db.framework.FrameworkSQLiteOpenHelper$OpenHelper.getWritableOrReadableDatabase(FrameworkSQLiteOpenHelper.kt:232)
	at androidx.sqlite.db.framework.FrameworkSQLiteOpenHelper$OpenHelper.innerGetDatabase(FrameworkSQLiteOpenHelper.kt:177)
	at androidx.sqlite.db.framework.FrameworkSQLiteOpenHelper$OpenHelper.getSupportDatabase(FrameworkSQLiteOpenHelper.kt:151)
	at androidx.sqlite.db.framework.FrameworkSQLiteOpenHelper.getWritableDatabase(FrameworkSQLiteOpenHelper.kt:104)
	at androidx.room.RoomDatabase.internalBeginTransaction(RoomDatabase.kt:522)
	at androidx.room.RoomDatabase.beginTransaction(RoomDatabase.kt:511)
	at app.pachli.core.database.dao.TimelineDao_Impl$23.call(TimelineDao_Impl.java:473)
	at app.pachli.core.database.dao.TimelineDao_Impl$23.call(TimelineDao_Impl.java:469)
	at androidx.room.CoroutinesRoom$Companion$execute$2.invokeSuspend(CoroutinesRoom.kt:64)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:104)
	at androidx.room.TransactionExecutor.execute$lambda$1$lambda$0(TransactionExecutor.kt:36)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
	at java.base/java.lang.Thread.run(Thread.java:833)

System.logW: A resource was acquired at attached stack trace but never released. See java.io.Closeable for information on avoiding resource leaks.
java.lang.Throwable: Explicit termination method 'close' not called
	at dalvik.system.CloseGuard.$$robo$$dalvik_system_CloseGuard$openWithCallSite(CloseGuard.java:288)
	at dalvik.system.CloseGuard.openWithCallSite(CloseGuard.java)
	at dalvik.system.CloseGuard.$$robo$$dalvik_system_CloseGuard$open(CloseGuard.java:257)
	at jdk.internal.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at org.robolectric.shadows.ShadowCloseGuard$CloseGuardReflector$$Reflector14.open(Unknown Source)
	at org.robolectric.shadows.ShadowCloseGuard.open(ShadowCloseGuard.java:38)
	at dalvik.system.CloseGuard.open(CloseGuard.java)
	at android.database.sqlite.SQLiteDatabase.$$robo$$android_database_sqlite_SQLiteDatabase$openInner(SQLiteDatabase.java:1086)
	at android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java)
	at android.database.sqlite.SQLiteDatabase.$$robo$$android_database_sqlite_SQLiteDatabase$open(SQLiteDatabase.java:1065)
	at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java)
	at android.database.sqlite.SQLiteDatabase.$$robo$$android_database_sqlite_SQLiteDatabase$openDatabase(SQLiteDatabase.java:929)
	at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java)
	at android.database.sqlite.SQLiteDatabase.$$robo$$android_database_sqlite_SQLiteDatabase$createInMemory(SQLiteDatabase.java:1125)
	at android.database.sqlite.SQLiteDatabase.createInMemory(SQLiteDatabase.java)
	at android.database.sqlite.SQLiteOpenHelper.$$robo$$android_database_sqlite_SQLiteOpenHelper$getDatabaseLocked(SQLiteOpenHelper.java:368)
	at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java)
	at android.database.sqlite.SQLiteOpenHelper.$$robo$$android_database_sqlite_SQLiteOpenHelper$getWritableDatabase(SQLiteOpenHelper.java:316)
	at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java)
	at androidx.sqlite.db.framework.FrameworkSQLiteOpenHelper$OpenHelper.getWritableOrReadableDatabase(FrameworkSQLiteOpenHelper.kt:232)
	at androidx.sqlite.db.framework.FrameworkSQLiteOpenHelper$OpenHelper.innerGetDatabase(FrameworkSQLiteOpenHelper.kt:177)
	at androidx.sqlite.db.framework.FrameworkSQLiteOpenHelper$OpenHelper.getSupportDatabase(FrameworkSQLiteOpenHelper.kt:151)
	at androidx.sqlite.db.framework.FrameworkSQLiteOpenHelper.getWritableDatabase(FrameworkSQLiteOpenHelper.kt:104)
	at androidx.room.RoomDatabase.internalBeginTransaction(RoomDatabase.kt:522)
	at androidx.room.RoomDatabase.beginTransaction(RoomDatabase.kt:511)
	at app.pachli.core.database.dao.TimelineDao_Impl$23.call(TimelineDao_Impl.java:473)
	at app.pachli.core.database.dao.TimelineDao_Impl$23.call(TimelineDao_Impl.java:469)
	at androidx.room.CoroutinesRoom$Companion$execute$2.invokeSuspend(CoroutinesRoom.kt:64)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:104)
	at androidx.room.TransactionExecutor.execute$lambda$1$lambda$0(TransactionExecutor.kt:36)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
	at java.base/java.lang.Thread.run(Thread.java:833)

System.logW: A resource was acquired at attached stack trace but never released. See java.io.Closeable for information on avoiding resource leaks.
java.lang.Throwable: Explicit termination method 'close' not called
	at dalvik.system.CloseGuard.$$robo$$dalvik_system_CloseGuard$openWithCallSite(CloseGuard.java:288)
	at dalvik.system.CloseGuard.openWithCallSite(CloseGuard.java)
	at dalvik.system.CloseGuard.$$robo$$dalvik_system_CloseGuard$open(CloseGuard.java:257)
	at jdk.internal.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at org.robolectric.shadows.ShadowCloseGuard$CloseGuardReflector$$Reflector14.open(Unknown Source)
	at org.robolectric.shadows.ShadowCloseGuard.open(ShadowCloseGuard.java:38)
	at dalvik.system.CloseGuard.open(CloseGuard.java)
	at android.database.sqlite.SQLiteDatabase.$$robo$$android_database_sqlite_SQLiteDatabase$openInner(SQLiteDatabase.java:1086)
	at android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java)
	at android.database.sqlite.SQLiteDatabase.$$robo$$android_database_sqlite_SQLiteDatabase$open(SQLiteDatabase.java:1065)
	at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java)
	at android.database.sqlite.SQLiteDatabase.$$robo$$android_database_sqlite_SQLiteDatabase$openDatabase(SQLiteDatabase.java:929)
	at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java)
	at android.database.sqlite.SQLiteDatabase.$$robo$$android_database_sqlite_SQLiteDatabase$createInMemory(SQLiteDatabase.java:1125)
	at android.database.sqlite.SQLiteDatabase.createInMemory(SQLiteDatabase.java)
	at android.database.sqlite.SQLiteOpenHelper.$$robo$$android_database_sqlite_SQLiteOpenHelper$getDatabaseLocked(SQLiteOpenHelper.java:368)
	at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java)
	at android.database.sqlite.SQLiteOpenHelper.$$robo$$android_database_sqlite_SQLiteOpenHelper$getWritableDatabase(SQLiteOpenHelper.java:316)
	at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java)
	at androidx.sqlite.db.framework.FrameworkSQLiteOpenHelper$OpenHelper.getWritableOrReadableDatabase(FrameworkSQLiteOpenHelper.kt:232)
	at androidx.sqlite.db.framework.FrameworkSQLiteOpenHelper$OpenHelper.innerGetDatabase(FrameworkSQLiteOpenHelper.kt:177)
	at androidx.sqlite.db.framework.FrameworkSQLiteOpenHelper$OpenHelper.getSupportDatabase(FrameworkSQLiteOpenHelper.kt:151)
	at androidx.sqlite.db.framework.FrameworkSQLiteOpenHelper.getWritableDatabase(FrameworkSQLiteOpenHelper.kt:104)
	at androidx.room.RoomDatabase.internalBeginTransaction(RoomDatabase.kt:522)
	at androidx.room.RoomDatabase.beginTransaction(RoomDatabase.kt:511)
	at app.pachli.core.database.dao.TimelineDao_Impl$23.call(TimelineDao_Impl.java:473)
	at app.pachli.core.database.dao.TimelineDao_Impl$23.call(TimelineDao_Impl.java:469)
	at androidx.room.CoroutinesRoom$Companion$execute$2.invokeSuspend(CoroutinesRoom.kt:64)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:104)
	at androidx.room.TransactionExecutor.execute$lambda$1$lambda$0(TransactionExecutor.kt:36)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
	at java.base/java.lang.Thread.run(Thread.java:833)

Maybe these messages are a bit annoying and should be resolved

Describe the solution you'd like
Maybe the db should be closed using the @After annotation ( I'm not sure).
However, it is possible that for some reason you are not intentionally close the db, so I want to get confirmation.

If this modification is needed, I will create a PR

@nikclayton
Copy link
Contributor

Ah, thanks for picking that up. Yes please, CachedTimelineRemoteMediatorTest shows what the correct fix should look like.

sanao1006 added a commit to sanao1006/pachli-android that referenced this issue Mar 8, 2024
To guarantee that DB was closed.

Fixes pachli#511
nikclayton pushed a commit that referenced this issue Mar 8, 2024
The previous code forgot to close the DB after TimelineDaoTest was run,
so a warning message was displayed when the test was run locally.

Close the database using the `@After` annotation.

Fixes #511
@github-project-automation github-project-automation bot moved this from Todo to Done in Pachli roadmap Mar 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants