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

Fix crash when refreshing feed after importing database or subscriptions #6639

Merged
merged 2 commits into from
Jul 10, 2021

Conversation

TobiGr
Copy link
Contributor

@TobiGr TobiGr commented Jul 10, 2021

What is it?

  • Bugfix (user facing)
  • Feature (user facing)
  • Codebase improvement (dev facing)
  • Meta improvement to the project (dev facing)

Description of the changes in your PR

Close database before restarting the app

Fixes the following issue(s)

Fixes crash when refreshing feed after importing database or subscriptions.

Exception

  • User Action: requested feed
  • Request: Loading feed
  • Content Country: US
  • Content Language: en
  • App Language: en_GB
  • Service: none
  • Version: 0.21.6
  • OS: Linux Android 10 - 29
Crash log

java.lang.NullPointerException: Attempt to invoke virtual method 'void org.schabi.newpipe.database.subscription.SubscriptionEntity.setName(java.lang.String)' on a null object reference
	at org.schabi.newpipe.local.subscription.SubscriptionManager.updateFromInfo(SubscriptionManager.kt:73)
	at org.schabi.newpipe.local.feed.service.FeedLoadService$databaseConsumer$1$1.run(FeedLoadService.kt:324)
	at androidx.room.RoomDatabase.runInTransaction(RoomDatabase.java:556)
	at org.schabi.newpipe.local.feed.service.FeedLoadService$databaseConsumer$1.accept(FeedLoadService.kt:316)
	at org.schabi.newpipe.local.feed.service.FeedLoadService$databaseConsumer$1.accept(FeedLoadService.kt:65)
	at io.reactivex.rxjava3.internal.operators.flowable.FlowableDoOnEach$DoOnEachSubscriber.onNext(FlowableDoOnEach.java:86)
	at io.reactivex.rxjava3.internal.operators.flowable.FlowableBuffer$PublisherBufferExactSubscriber.onNext(FlowableBuffer.java:124)
	at io.reactivex.rxjava3.internal.operators.flowable.FlowableObserveOn$ObserveOnSubscriber.runAsync(FlowableObserveOn.java:402)
	at io.reactivex.rxjava3.internal.operators.flowable.FlowableObserveOn$BaseObserveOnSubscriber.run(FlowableObserveOn.java:176)
	at io.reactivex.rxjava3.internal.schedulers.ScheduledRunnable.run(ScheduledRunnable.java:65)
	at io.reactivex.rxjava3.internal.schedulers.ScheduledRunnable.call(ScheduledRunnable.java:56)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:301)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
	at java.lang.Thread.run(Thread.java:919)

APK testing

The APK can be found by going to the "Checks" tab below the title. On the left pane, click on "CI", scroll down to "artifacts" and click "app" to download the zip file which contains the debug APK of this PR.

Due diligence

@TobiGr TobiGr added the bug Issue is related to a bug label Jul 10, 2021
@TobiGr TobiGr mentioned this pull request Jul 10, 2021
@XiangRongLin
Copy link
Collaborator

With those changes I get this, after importing the db

Exception

  • User Action: requested feed
  • Request: Loading feed
  • Content Country: US
  • Content Language: en-US
  • App Language: en_US
  • Service: none
  • Version: 0.21.5
  • OS: Linux Android 11 - 30
Crash log

java.lang.IllegalStateException: The database '/data/user/0/org.schabi.newpipe.debug/databases/newpipe.db' is not open.
	at android.database.sqlite.SQLiteDatabase.throwIfNotOpenLocked(SQLiteDatabase.java:2482)
	at android.database.sqlite.SQLiteDatabase.createSession(SQLiteDatabase.java:430)
	at android.database.sqlite.-$$Lambda$RBWjWVyGrOTsQrLCYzJ_G8Uk25Q.get(Unknown Source:2)
	at java.lang.ThreadLocal$SuppliedThreadLocal.initialValue(ThreadLocal.java:284)
	at java.lang.ThreadLocal.setInitialValue(ThreadLocal.java:180)
	at java.lang.ThreadLocal.get(ThreadLocal.java:170)
	at android.database.sqlite.SQLiteDatabase.getThreadSession(SQLiteDatabase.java:424)
	at android.database.sqlite.SQLiteProgram.getSession(SQLiteProgram.java:104)
	at android.database.sqlite.SQLiteStatement.executeUpdateDelete(SQLiteStatement.java:66)
	at androidx.sqlite.db.framework.FrameworkSQLiteStatement.executeUpdateDelete(FrameworkSQLiteStatement.java:46)
	at org.schabi.newpipe.database.feed.dao.FeedDAO_Impl.unlinkOldLivestreams(FeedDAO_Impl.java:255)
	at org.schabi.newpipe.local.feed.FeedDatabaseManager.upsertAll(FeedDatabaseManager.kt:91)
	at org.schabi.newpipe.local.feed.FeedDatabaseManager.upsertAll$default(FeedDatabaseManager.kt:78)
	at org.schabi.newpipe.local.feed.service.FeedLoadService$databaseConsumer$1$1.run(FeedLoadService.kt:323)
	at androidx.room.RoomDatabase.runInTransaction(RoomDatabase.java:556)
	at org.schabi.newpipe.local.feed.service.FeedLoadService$databaseConsumer$1.accept(FeedLoadService.kt:316)
	at org.schabi.newpipe.local.feed.service.FeedLoadService$databaseConsumer$1.accept(FeedLoadService.kt:65)
	at io.reactivex.rxjava3.internal.operators.flowable.FlowableDoOnEach$DoOnEachSubscriber.onNext(FlowableDoOnEach.java:86)
	at io.reactivex.rxjava3.internal.operators.flowable.FlowableBuffer$PublisherBufferExactSubscriber.onNext(FlowableBuffer.java:124)
	at io.reactivex.rxjava3.internal.operators.flowable.FlowableObserveOn$ObserveOnSubscriber.runAsync(FlowableObserveOn.java:402)
	at io.reactivex.rxjava3.internal.operators.flowable.FlowableObserveOn$BaseObserveOnSubscriber.run(FlowableObserveOn.java:176)
	at io.reactivex.rxjava3.internal.schedulers.ScheduledRunnable.run(ScheduledRunnable.java:65)
	at io.reactivex.rxjava3.internal.schedulers.ScheduledRunnable.call(ScheduledRunnable.java:56)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:301)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
	at java.lang.Thread.run(Thread.java:923)


@XiangRongLin
Copy link
Collaborator

Inside NewPipeDatabase add this method and use that to close the db. This way when getInstance is called a new instance is created.

    public static void close() {
        if (databaseInstance != null) {
            synchronized (NewPipeDatabase.class) {
                if (databaseInstance != null) {
                    databaseInstance.close();
                    databaseInstance = null;
                }
            }
        }
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue is related to a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants