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

Remove Warning log when persisted user file not loaded #1906

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions bugsnag-android-core/detekt-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
<ID>MagicNumber:LastRunInfoStore.kt$LastRunInfoStore$3</ID>
<ID>MaxLineLength:LastRunInfo.kt$LastRunInfo$return "LastRunInfo(consecutiveLaunchCrashes=$consecutiveLaunchCrashes, crashed=$crashed, crashedDuringLaunch=$crashedDuringLaunch)"</ID>
<ID>MaxLineLength:ThreadState.kt$ThreadState$"[${allThreads.size - maxThreadCount} threads omitted as the maxReportedThreads limit ($maxThreadCount) was exceeded]"</ID>
<ID>MaxLineLength:UserStore.kt$UserStore$}</ID>
<ID>NestedBlockDepth:JsonHelper.kt$JsonHelper$fun jsonToLong(value: Any?): Long?</ID>
<ID>ProtectedMemberInFinalClass:ConfigInternal.kt$ConfigInternal$protected val plugins = HashSet&lt;Plugin>()</ID>
<ID>ProtectedMemberInFinalClass:EventInternal.kt$EventInternal$protected fun isAnr(event: Event): Boolean</ID>
Expand All @@ -51,6 +52,7 @@
<ID>SwallowedException:JsonHelperTest.kt$JsonHelperTest$e: IllegalArgumentException</ID>
<ID>SwallowedException:PluginClient.kt$PluginClient$exc: ClassNotFoundException</ID>
<ID>SwallowedException:SharedPrefMigrator.kt$SharedPrefMigrator$e: RuntimeException</ID>
<ID>SwallowedException:UserStore.kt$UserStore$e: Exception</ID>
<ID>ThrowsCount:JsonHelper.kt$JsonHelper$fun jsonToLong(value: Any?): Long?</ID>
<ID>TooManyFunctions:ConfigInternal.kt$ConfigInternal : CallbackAwareMetadataAwareUserAwareFeatureFlagAware</ID>
<ID>TooManyFunctions:DeviceDataCollector.kt$DeviceDataCollector</ID>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ internal class UserStoreTest {
/**
* If persistUser is false a user is still returned
*/
@Test
@Test(expected = Exception::class)
fun loadWithoutPersistUser() {
val store = UserStore(
generateConfig(false),
Expand All @@ -145,21 +145,18 @@ internal class UserStoreTest {
prefMigrator,
NoopLogger
)
val user = store.load(User()).user
assertEquals("device-id-123", user.id)
assertNull(user.email)
assertNull(user.name)
assertEquals("", file.readText())
store.load(User()).user
file.readText()
}

/**
* If persistUser is false a user is not saved
*/
@Test
@Test(expected = Exception::class)
fun saveWithoutPersistUser() {
val store = UserStore(generateConfig(false), "", file, prefMigrator, NoopLogger)
store.save(User("123", "[email protected]", "Joe Bloggs"))
assertEquals("", file.readText())
file.readText()
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import kotlin.concurrent.withLock
* This class is made thread safe through the use of a [ReadWriteLock].
*/
internal class SynchronizedStreamableStore<T : JsonStream.Streamable>(
private val file: File
internal val file: File
) {

private val lock = ReentrantReadWriteLock()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package com.bugsnag.android
import com.bugsnag.android.internal.ImmutableConfig
import com.bugsnag.android.internal.StateObserver
import java.io.File
import java.io.IOException
import java.util.concurrent.atomic.AtomicReference

/**
Expand All @@ -22,11 +21,6 @@ internal class UserStore @JvmOverloads constructor(
private val previousUser = AtomicReference<User?>(null)

init {
try {
file.createNewFile()
} catch (exc: IOException) {
logger.w("Failed to created device ID file", exc)
}
this.synchronizedStreamableStore = SynchronizedStreamableStore(file)
}

Expand Down Expand Up @@ -87,13 +81,15 @@ internal class UserStore @JvmOverloads constructor(
val legacyUser = sharedPrefMigrator.loadUser(deviceId)
save(legacyUser)
legacyUser
} else {
return try {
} else if (synchronizedStreamableStore.file.canRead() && synchronizedStreamableStore.file.length() > 0L && persist) {
try {
synchronizedStreamableStore.load(User.Companion::fromReader)
} catch (exc: Exception) {
logger.w("Failed to load user info", exc)
} catch (e: Exception) {
logger.w("Failed to load user info")
null
}
} else {
null
}
}
}