Skip to content

Commit 6844c1f

Browse files
committed
Address detekt changes
- Baseline 2 new UseCheckOrError entries for OneSignalImp.kt for updateUserJwt/updateUserJwtSuspend init guards that follow the existing login/logout pattern. - Baseline ReturnCount for hasValidJwtIfRequired — the guard-clause style is clearer than collapsing into a single boolean expression for this JWT gating logic. - Narrow JwtTokenStore catch from Exception to JSONException to satisfy detekt's TooGenericExceptionCaught rule, no baseline added.
1 parent 16ce7f6 commit 6844c1f

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

OneSignalSDK/detekt/detekt-baseline-core.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@
279279
<ID>PrintStackTrace:TrackGooglePurchase.kt$TrackGooglePurchase$e</ID>
280280
<ID>PrintStackTrace:TrackGooglePurchase.kt$TrackGooglePurchase.&lt;no name provided>$t</ID>
281281
<ID>RethrowCaughtException:OSDatabase.kt$OSDatabase$throw e</ID>
282+
<ID>ReturnCount:OperationRepo.kt$OperationRepo$private fun hasValidJwtIfRequired( identityVerificationEnabled: Boolean, op: Operation, ): Boolean</ID>
282283
<ID>ReturnCount:AppIdResolution.kt$fun resolveAppId( inputAppId: String?, configModel: ConfigModel, preferencesService: IPreferencesService, ): AppIdResolution</ID>
283284
<ID>ReturnCount:BackgroundManager.kt$BackgroundManager$override fun cancelRunBackgroundServices(): Boolean</ID>
284285
<ID>ReturnCount:OneSignalImp.kt$OneSignalImp$private fun internalInit( context: Context, appId: String?, ): Boolean</ID>
@@ -609,6 +610,8 @@
609610
<ID>UnusedPrivateMember:OperationRepo.kt$OperationRepo$private val _time: ITime</ID>
610611
<ID>UseCheckOrError:OneSignalImp.kt$OneSignalImp$throw IllegalStateException("'initWithContext failed' before 'login'")</ID>
611612
<ID>UseCheckOrError:OneSignalImp.kt$OneSignalImp$throw IllegalStateException("'initWithContext failed' before 'logout'")</ID>
613+
<ID>UseCheckOrError:OneSignalImp.kt$OneSignalImp$throw IllegalStateException("'initWithContext failed' before 'updateUserJwt'")</ID>
614+
<ID>UseCheckOrError:OneSignalImp.kt$OneSignalImp$throw IllegalStateException("Must call 'initWithContext' before 'updateUserJwt'")</ID>
612615
<ID>UseCheckOrError:OneSignalImp.kt$OneSignalImp$throw initFailureException ?: IllegalStateException("Initialization failed. Cannot proceed.")</ID>
613616
</CurrentIssues>
614617
</SmellBaseline>

OneSignalSDK/onesignal/core/src/main/java/com/onesignal/core/internal/operations/impl/OperationRepo.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -431,11 +431,10 @@ internal class OperationRepo(
431431
* also held because they cannot be authenticated.
432432
*/
433433
private fun hasValidJwtIfRequired(
434-
iv: Boolean,
434+
identityVerificationEnabled: Boolean,
435435
op: Operation,
436436
): Boolean {
437-
if (!iv) return true
438-
if (!op.requiresJwt) return true
437+
if (!identityVerificationEnabled || !op.requiresJwt) return true
439438
val externalId = op.externalId ?: return false
440439
return _jwtTokenStore.getJwt(externalId) != null
441440
}

OneSignalSDK/onesignal/core/src/main/java/com/onesignal/user/internal/identity/JwtTokenStore.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import com.onesignal.core.internal.preferences.IPreferencesService
44
import com.onesignal.core.internal.preferences.PreferenceOneSignalKeys
55
import com.onesignal.core.internal.preferences.PreferenceStores
66
import com.onesignal.debug.internal.logging.Logging
7+
import org.json.JSONException
78
import org.json.JSONObject
89

910
/**
@@ -34,7 +35,7 @@ class JwtTokenStore(
3435
for (key in obj.keys()) {
3536
tokens[key] = obj.getString(key)
3637
}
37-
} catch (e: Exception) {
38+
} catch (e: JSONException) {
3839
Logging.warn("JwtTokenStore: failed to parse persisted tokens, starting fresh", e)
3940
}
4041
}

0 commit comments

Comments
 (0)