Skip to content

Commit 95786cb

Browse files
committed
Refine
1 parent 340b104 commit 95786cb

1 file changed

Lines changed: 29 additions & 29 deletions

File tree

‎sentry-android-navigation3/src/main/kotlin/io/sentry/compose/navigation3/internal/backstack/kotlinx/KotlinxCompatibilityProbe.kt‎

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,19 @@ import kotlinx.serialization.Serializable
1616
*
1717
* **Disambiguating serializer errors from library incompatibility**
1818
*
19-
* Without a check like this, `KotlinxBackStackEntryMapper` would have to infer an incompatible
20-
* kotlinx.serialization version from [LinkageError]s thrown while handling the host app's own back
21-
* stack entry types. But such errors can also come from the host app's serializer code, and should
22-
* therefore only fail for the entry types that can't be deserialized. `ProbeClass` and
23-
* `ProbeObject` don't execute any host app code, so a `LinkageError` while handling them means the
24-
* app's kotlinx.serialization version is incompatible.
19+
* A [LinkageError] while handling a host app's back stack entry may come from that entry's
20+
* serializer, so it mustn't disable mapping for other types. The SDK-owned `ProbeClass` and
21+
* `ProbeObject` run no host app code, letting us check kotlinx.serialization compatibility
22+
* independently.
2523
*
26-
* Note: For the name lookup check ([nameLookupLinkageError]), only a `LinkageError` is conclusive.
27-
* Any other failure, or a probe type whose serializer can't be found, leaves it inconclusive: it's
28-
* reported to the caller's `onInconclusive` and otherwise ignored, as a real type that hits the
29-
* same failure is handled and logged on its own. The encoder check ([encoderIncompatibility])
30-
* instead treats any failure as conclusive, because a broken encoder can record wrong arguments
31-
* without throwing, and recording wrong arguments is worse than recording none.
24+
* The checks use different failure policies:
25+
*
26+
* - [nameLookupLinkageError]: only a [LinkageError] establishes incompatibility. Other failures,
27+
* including a missing probe serializer, are reported through `onInconclusive`. Mapping continues,
28+
* and failures for real entry types are handled and logged individually.
29+
*
30+
* - [encoderIncompatibility]: any exception or incorrect output disables property encoding. A
31+
* broken encoder can silently record wrong arguments, so recording none is safer.
3232
*/
3333
internal interface KotlinxCompatibilityProbe {
3434

@@ -48,12 +48,10 @@ internal interface KotlinxCompatibilityProbe {
4848
* Encodes [ProbeClass] using the same path as [KotlinxBackStackEntryMapper], checks that it links
4949
* and runs, and verifies its output matches the known fixture.
5050
*
51-
* Returns the error that makes the properties encoder unusable, or `null` if encoding succeeds
52-
* and matches. Unlike [nameLookupLinkageError], any failure is conclusive: an incompatible
53-
* kotlinx.serialization version can fail the encoder without a [LinkageError] (for instance, an
54-
* API-incompatible encoder can throw a [NullPointerException] under R8) or mis-encode without
55-
* throwing at all, and the caller disables property encoding on any failure here rather than risk
56-
* recording wrong arguments.
51+
* Returns an error if encoding fails or produces unexpected arguments, and `null` otherwise.
52+
* Unlike [nameLookupLinkageError], every failure disables property encoding. An incompatible
53+
* kotlinx.serialization version may throw something other than [LinkageError] (e.g.,
54+
* [NullPointerException] under R8), or silently encode incorrect arguments.
5755
*/
5856
fun encoderIncompatibility(): Throwable?
5957

@@ -152,25 +150,27 @@ internal interface KotlinxCompatibilityProbe {
152150
)
153151

154152
/**
155-
* A known serializable object used to test serializer lookup for the host app's object-based
156-
* back stack entries. This lookup reads the object's singleton instance.
153+
* [ProbeClass]'s expected encoding.
154+
*
155+
* A kotlinx.serialization version that encodes it to anything else mis-encodes properties and
156+
* must not be used. None of the keys are on the sensitive denylist, so none are filtered.
157157
*/
158-
@Serializable internal object ProbeObject
158+
private val EXPECTED_PROBE_ENCODING: Map<String, Any?> =
159+
mapOf("name" to "probe", "values" to listOf(1), "counts" to mapOf("count" to 1))
159160

160161
/**
161-
* [ProbeClass]'s expected encoding. A kotlinx.serialization version that encodes it to anything
162-
* else mis-encodes properties and must not be used. None of the keys are on the sensitive
163-
* denylist, so none are filtered.
162+
* A known serializable object used to test serializer lookup for the host app's object-based
163+
* back stack entries. This lookup reads the object's singleton instance.
164164
*/
165-
private val EXPECTED_PROBE_ENCODING: Map<String, Any?> =
166-
mapOf("name" to "probe", "values" to listOf(1), "counts" to mapOf("count" to 1))
165+
@Serializable internal object ProbeObject
167166
}
168167
}
169168

170169
/**
171-
* Signals that the properties encoder ran but produced output that didn't match the SDK's own
172-
* `ProbeClass` fixture, so the app's kotlinx.serialization version mis-encodes properties. Carries
173-
* only a fixed message, never route data: the fixture is the SDK's own.
170+
* Signals that the encoder produced unexpected arguments for the SDK-owned `ProbeClass`, indicating
171+
* incompatible kotlinx.serialization behavior.
172+
*
173+
* Carries a fixed message with no (potentially sensitive) back stack entry data.
174174
*/
175175
internal class EncoderProducedUnexpectedOutput :
176176
RuntimeException(

0 commit comments

Comments
 (0)