Skip to content
This repository was archived by the owner on Feb 4, 2025. It is now read-only.

Commit dd8ac78

Browse files
committed
Analysis: Resolve use check or error warning for activitylog rest client
Description: "Kotlin provides a concise way to check invariants as well as pre- and post-conditions. Prefer them instead of manually throwing an IllegalStateException." For more info see: https://detekt.dev/docs/rules/style/#usecheckorerror
1 parent 6bc8592 commit dd8ac78

File tree

2 files changed

+2
-3
lines changed

2 files changed

+2
-3
lines changed

config/detekt/baseline.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@
131131
<ID>TooGenericExceptionCaught:WPV2MediaRestClient.kt$WPV2MediaRestClient.&lt;no name provided>$e: NullPointerException</ID>
132132
<ID>TooGenericExceptionThrown:ScanStore.kt$ScanStore$throw RuntimeException(msg)</ID>
133133
<ID>TooGenericExceptionThrown:WPAPIEncodedBodyRequest.kt$WPAPIEncodedBodyRequest$throw RuntimeException("Encoding not supported: $paramsEncoding", uee)</ID>
134-
<ID>UseCheckOrError:ActivityLogRestClient.kt$ActivityLogRestClient$throw IllegalStateException("ActivityTypes parsing failed - one or more items were ignored.")</ID>
135134
<ID>UtilityClassWithPublicConstructor:EncryptionUtils.kt$EncryptionUtils</ID>
136135
<ID>UtilityClassWithPublicConstructor:WhatsNewAppVersionUtils.kt$WhatsNewAppVersionUtils</ID>
137136
<ID>VariableNaming:AuthOptionsResponse.kt$AuthOptionsResponse$var email_verified: Boolean? = null</ID>

fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/activity/ActivityLogRestClient.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -418,8 +418,8 @@ class ActivityLogRestClient @Inject constructor(
418418
?.map { ActivityTypeModel(requireNotNull(it.key), requireNotNull(it.name), it.count ?: 0) }
419419
?: listOf()
420420

421-
if (BuildConfig.DEBUG && (response.groups?.activityTypes?.size ?: 0) != activityTypes.size) {
422-
throw IllegalStateException("ActivityTypes parsing failed - one or more items were ignored.")
421+
check(!BuildConfig.DEBUG || (response.groups?.activityTypes?.size ?: 0) == activityTypes.size) {
422+
"ActivityTypes parsing failed - one or more items were ignored."
423423
}
424424

425425
return FetchedActivityTypesResultPayload(

0 commit comments

Comments
 (0)