Skip to content

8.19+ lost compatibility with API older than 26? #4651

@mauriciospinardi-cloudwalk

Description

Integration

sentry-android

Build System

Gradle

AGP Version

8.12.1

Proguard

Enabled

Version

8.19.1

Steps to Reproduce

Just noticed a crash on a device running Android 5.1 (API 22). Upon further analysis, it seems we have an addition to SentryTraceHeader that could be the cause. The crash does not seem to happen in older versions:

Possible culprit:

private static final Pattern SENTRY_TRACEPARENT_HEADER_REGEX =
      Pattern.compile(
          "^[ \\t]*(?<traceId>[0-9a-f]{32})-(?<spanId>[0-9a-f]{16})(?<sampled>-[01])?[ \\t]*$",
          Pattern.CASE_INSENSITIVE);

(AI) The regex pattern uses named capturing groups ((?<traceId>, (?<spanId>, (?<sampled>), which were only added to Android's Pattern class in API 26 (Android 8.0).

Was that intentional?

Expected Result

Release 8.19.1 should work just fine on devices with API 22.

Actual Result

Release 8.19.1 crashes the application when running on devices with API 22.

Process: io.cloudwalk.appclientcw, PID: 4128
java.lang.ExceptionInInitializerError
	at kotlin.random.RandomKt.traceIfAllowed(r8-map-id-af09a800d99bce4296167a985f9f674ea32b4cb61321121f585812368ad730f8:83)
	at io.sentry.okhttp.SentryOkHttpInterceptor.intercept(r8-map-id-af09a800d99bce4296167a985f9f674ea32b4cb61321121f585812368ad730f8:175)
	at okhttp3.internal.http.RealInterceptorChain.proceed(r8-map-id-af09a800d99bce4296167a985f9f674ea32b4cb61321121f585812368ad730f8:128)
	at io.cloudwalk.core.client.communication.retrofit.JsonInterceptor.intercept(r8-map-id-af09a800d99bce4296167a985f9f674ea32b4cb61321121f585812368ad730f8:45)
	at okhttp3.internal.http.RealInterceptorChain.proceed(r8-map-id-af09a800d99bce4296167a985f9f674ea32b4cb61321121f585812368ad730f8:128)
	at okhttp3.internal.connection.RealCall.getResponseWithInterceptorChain$okhttp(r8-map-id-af09a800d99bce4296167a985f9f674ea32b4cb61321121f585812368ad730f8:123)
	at okhttp3.internal.connection.RealCall$AsyncCall.run(r8-map-id-af09a800d99bce4296167a985f9f674ea32b4cb61321121f585812368ad730f8:48)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
	at java.lang.Thread.run(Thread.java:818)
Caused by: java.util.regex.PatternSyntaxException: Syntax error in regexp pattern near index 12:
^[ \t]*(?<traceId>[0-9a-f]{32})-(?<spanId>[0-9a-f]{16})(?<sampled>-[01])?[ \t]*$
			^
	at java.util.regex.Pattern.compileImpl(Native Method)
	at java.util.regex.Pattern.compile(Pattern.java:411)
	at java.util.regex.Pattern.<init>(Pattern.java:394)
	at java.util.regex.Pattern.compile(Pattern.java:374)
	at io.sentry.SentryTraceHeader.<clinit>(r8-map-id-af09a800d99bce4296167a985f9f674ea32b4cb61321121f585812368ad730f8:4)
	... 10 more

Metadata

Metadata

Assignees

No one assigned

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions