Skip to content
This repository has been archived by the owner on Dec 14, 2021. It is now read-only.

Commit

Permalink
867 - Fix obvious NPE sync crash (#884)
Browse files Browse the repository at this point in the history
  • Loading branch information
jhugman authored Aug 22, 2019
1 parent b44f13c commit 4a3226d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
16 changes: 13 additions & 3 deletions app/src/main/java/mozilla/lockbox/store/DataStore.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

package mozilla.lockbox.store

import androidx.annotation.VisibleForTesting
import com.jakewharton.rxrelay2.BehaviorRelay
import com.jakewharton.rxrelay2.ReplayRelay
import io.reactivex.Observable
Expand Down Expand Up @@ -60,7 +61,8 @@ open class DataStore(

internal val compositeDisposable = CompositeDisposable()
private val stateSubject = ReplayRelay.createWithSize<State>(1)
private val syncStateSubject = BehaviorRelay.createDefault<SyncState>(SyncState.NotSyncing)
@VisibleForTesting
val syncStateSubject: BehaviorRelay<SyncState> = BehaviorRelay.createDefault(SyncState.NotSyncing)
private val listSubject: BehaviorRelay<List<ServerPassword>> = BehaviorRelay.createDefault(emptyList())
private val deletedItemSubject = ReplayRelay.create<Consumable<ServerPassword>>()

Expand Down Expand Up @@ -235,13 +237,21 @@ open class DataStore(
}
}

private fun sync() {
@VisibleForTesting(
otherwise = VisibleForTesting.PRIVATE
)
fun sync() {
resetSupport(support)

val syncConfig = support.syncConfig ?: run {
log.error("syncConfig is null in sync. This is likely a bug.")
return
}

// ideally, we don't sync unless we are connected to the network
syncStateSubject.accept(SyncState.Syncing)

backend.sync(support.syncConfig!!)
backend.sync(syncConfig)
.asSingle(coroutineContext)
.map {
log.debug("Hashed UID: $it")
Expand Down
9 changes: 9 additions & 0 deletions app/src/test/java/mozilla/lockbox/store/DataStoreTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ class DataStoreTest : DisposingTest() {
subject = DataStore(dispatcher, support, timingSupport, lifecycleStore)
}

@Test
fun `test issue 867 sync crash`() {
support.syncConfig = null
Assert.assertNull(support.syncConfig)
subject.sync()
Assert.assertNull(support.syncConfig)
Assert.assertEquals(subject.syncStateSubject.value, DataStore.SyncState.NotSyncing)
}

@Test
fun testLockUnlock_shouldSync() {
val stateIterator = this.subject.state.blockingIterable().iterator()
Expand Down

0 comments on commit 4a3226d

Please sign in to comment.