Skip to content

Commit 4a82e80

Browse files
runningcodeclaude
andcommitted
ref: Leave callback and LinkageError-prone sites to the other PRs
Sites whose try wraps user or hybrid callbacks, or code from compileOnly modules, can see a LinkageError that is not fatal there, so they move to #6666, which handles it at the call site. The screenshot and replay capture sites move to the bitmap OOM PR, and the callback Javadoc moves with the sites it describes. Refs #5513 Refs JAVA-552 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent d79261d commit 4a82e80

32 files changed

Lines changed: 4 additions & 322 deletions

File tree

‎sentry-android-core/src/main/java/io/sentry/android/core/SentryAndroid.java‎

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import io.sentry.android.fragment.FragmentLifecycleIntegration;
2121
import io.sentry.android.timber.SentryTimberIntegration;
2222
import io.sentry.util.AutoClosableReentrantLock;
23-
import io.sentry.util.ExceptionUtils;
2423
import io.sentry.util.LoadClass;
2524
import java.lang.reflect.InvocationTargetException;
2625
import java.util.ArrayList;
@@ -80,11 +79,6 @@ public static void init(@NotNull final Context context, @NotNull ILogger logger)
8079
/**
8180
* Sentry initialization with a configuration handler that may override the default options
8281
*
83-
* <p>If the configuration handler throws, init continues with the options it set before it
84-
* failed. Fatal errors such as {@link OutOfMemoryError} are rethrown instead. The failure is only
85-
* logged at ERROR level through the SDK logger, which prints only when debug is enabled, e.g.
86-
* through the {@code io.sentry.debug} manifest entry.
87-
*
8882
* @param context Application. context
8983
* @param configuration Sentry.OptionsConfiguration configuration handler
9084
*/
@@ -97,11 +91,6 @@ public static void init(
9791
/**
9892
* Sentry initialization with a configuration handler and custom logger
9993
*
100-
* <p>If the configuration handler throws, init continues with the options it set before it
101-
* failed. Fatal errors such as {@link OutOfMemoryError} are rethrown instead. The failure is only
102-
* logged at ERROR level through the SDK logger, which prints only when debug is enabled, e.g.
103-
* through the {@code io.sentry.debug} manifest entry.
104-
*
10594
* @param context Application. context
10695
* @param logger your custom logger that implements ILogger
10796
* @param configuration Sentry.OptionsConfiguration configuration handler
@@ -162,9 +151,7 @@ public static void init(
162151
try {
163152
configuration.configure(options);
164153
} catch (Throwable t) {
165-
// The configuration callback is the app's own code, so we can't know what it
166-
// throws. Init continues with the options set before it failed.
167-
ExceptionUtils.rethrowIfFatal(t);
154+
// let it slip, but log it
168155
options
169156
.getLogger()
170157
.log(

‎sentry-android-core/src/main/java/io/sentry/android/core/internal/util/ScreenshotUtils.java‎

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,7 @@ public final class ScreenshotUtils {
184184
final boolean completed = latch.await(CAPTURE_TIMEOUT_MS, TimeUnit.MILLISECONDS);
185185
success = completed && copyResultCode.get() == PixelCopy.SUCCESS;
186186
} catch (Throwable e) {
187-
// PixelCopy reads the window's surface through the system compositor, so we can't know
188-
// what it throws. No screenshot is attached.
189-
ExceptionUtils.rethrowIfFatal(e);
187+
// ignored
190188
logger.log(SentryLevel.ERROR, "Taking screenshot using PixelCopy failed.", e);
191189
} finally {
192190
thread.quit();
@@ -209,9 +207,6 @@ public final class ScreenshotUtils {
209207
try {
210208
view.draw(canvas);
211209
} catch (Throwable e) {
212-
// draw() runs the app's own views, so we can't know what it throws. No screenshot is
213-
// attached.
214-
ExceptionUtils.rethrowIfFatal(e);
215210
logger.log(SentryLevel.ERROR, "Taking screenshot failed (view.draw).", e);
216211
} finally {
217212
latch.countDown();
@@ -225,9 +220,6 @@ public final class ScreenshotUtils {
225220
}
226221
return bitmap;
227222
} catch (Throwable e) {
228-
// On the main thread, draw() runs the app's own views, so we can't know what it throws. No
229-
// screenshot is attached.
230-
ExceptionUtils.rethrowIfFatal(e);
231223
logger.log(SentryLevel.ERROR, "Taking screenshot failed.", e);
232224
}
233225
return null;

‎sentry-android-replay/src/main/java/io/sentry/android/replay/ReplayIntegration.kt‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ import io.sentry.protocol.SentryId
5151
import io.sentry.transport.ICurrentDateProvider
5252
import io.sentry.transport.RateLimiter
5353
import io.sentry.transport.RateLimiter.IRateLimitObserver
54-
import io.sentry.util.ExceptionUtils
5554
import io.sentry.util.FileUtils
5655
import io.sentry.util.HintUtils
5756
import io.sentry.util.IntegrationUtils.addIntegrationToSdkVersion
@@ -488,9 +487,6 @@ public class ReplayIntegration(
488487
hint.set(TypeCheckHint.REPLAY_FRAME_BITMAP, copy)
489488
observer.onMaskedFrameCaptured(hint, frameTimeStamp, screen)
490489
} catch (e: Throwable) {
491-
// The observer is the app's own code, so we can't know what it throws. The copy is
492-
// recycled and the frame is still recorded.
493-
ExceptionUtils.rethrowIfFatal(e)
494490
options.logger.log(ERROR, "Error in ReplayFrameObserver", e)
495491
copy.recycle()
496492
}
@@ -514,9 +510,6 @@ public class ReplayIntegration(
514510
hint.set(TypeCheckHint.REPLAY_FRAME_BITMAP, bitmap)
515511
observer.onMaskedFrameCaptured(hint, frameTimestamp, screen)
516512
} catch (e: Throwable) {
517-
// The observer is the app's own code, so we can't know what it throws. The bitmap is
518-
// recycled and the frame is still recorded.
519-
ExceptionUtils.rethrowIfFatal(e)
520513
options.logger.log(ERROR, "Error in ReplayFrameObserver", e)
521514
bitmap.recycle()
522515
}

‎sentry-android-replay/src/main/java/io/sentry/android/replay/ScreenshotRecorder.kt‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import io.sentry.android.replay.screenshot.ScreenshotStrategy
1717
import io.sentry.android.replay.util.DebugOverlayDrawable
1818
import io.sentry.android.replay.util.addOnDrawListenerSafe
1919
import io.sentry.android.replay.util.removeOnDrawListenerSafe
20-
import io.sentry.util.ExceptionUtils
2120
import java.io.File
2221
import java.lang.ref.WeakReference
2322
import java.util.concurrent.atomic.AtomicBoolean
@@ -93,9 +92,6 @@ internal class ScreenshotRecorder(
9392
contentChanged.set(false)
9493
screenshotStrategy.capture(root)
9594
} catch (e: Throwable) {
96-
// Capturing draws the app's own views and goes through the device's graphics stack, so we
97-
// can't know what it throws. The frame is skipped.
98-
ExceptionUtils.rethrowIfFatal(e)
9995
options.logger.log(WARNING, "Failed to capture replay recording", e)
10096
}
10197
}

‎sentry-android-replay/src/main/java/io/sentry/android/replay/WindowRecorder.kt‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import io.sentry.android.replay.util.addOnPreDrawListenerSafe
1616
import io.sentry.android.replay.util.hasSize
1717
import io.sentry.android.replay.util.removeOnPreDrawListenerSafe
1818
import io.sentry.util.AutoClosableReentrantLock
19-
import io.sentry.util.ExceptionUtils
2019
import java.lang.ref.WeakReference
2120
import java.util.WeakHashMap
2221
import java.util.concurrent.ScheduledExecutorService
@@ -97,9 +96,6 @@ internal class WindowRecorder(
9796
}
9897
recorder?.capture()
9998
} catch (e: Throwable) {
100-
// Capturing draws the app's own views and goes through the device's graphics stack, so we
101-
// can't know what it throws. This frame is skipped, and the next one is still scheduled.
102-
ExceptionUtils.rethrowIfFatal(e)
10399
options.logger.log(ERROR, "Failed to capture a frame", e)
104100
}
105101

‎sentry-android-replay/src/main/java/io/sentry/android/replay/screenshot/CanvasStrategy.kt‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ import io.sentry.android.replay.ScreenshotRecorderCallback
3636
import io.sentry.android.replay.ScreenshotRecorderConfig
3737
import io.sentry.android.replay.util.ReplayRunnable
3838
import io.sentry.util.AutoClosableReentrantLock
39-
import io.sentry.util.ExceptionUtils
4039
import io.sentry.util.IntegrationUtils
4140
import java.util.WeakHashMap
4241
import java.util.concurrent.atomic.AtomicBoolean
@@ -145,9 +144,6 @@ internal class CanvasStrategy(
145144
executor.getBackgroundHandler(),
146145
)
147146
} catch (t: Throwable) {
148-
// Drawing into the hardware surface and PixelCopy go through the device's graphics stack,
149-
// so we can't know what they throw. The frame is skipped.
150-
ExceptionUtils.rethrowIfFatal(t)
151147
// if the request itself threw, no callback will clear the flag
152148
pixelCopyInFlight = false
153149
options.logger.log(SentryLevel.ERROR, "Canvas Strategy: picture render failed", t)

‎sentry-android-replay/src/main/java/io/sentry/android/replay/screenshot/PixelCopyStrategy.kt‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import io.sentry.android.replay.util.MaskRenderer
2424
import io.sentry.android.replay.util.ReplayRunnable
2525
import io.sentry.android.replay.util.traverse
2626
import io.sentry.android.replay.viewhierarchy.ViewHierarchyNode
27-
import io.sentry.util.ExceptionUtils
2827
import java.util.concurrent.atomic.AtomicBoolean
2928
import java.util.concurrent.atomic.AtomicInteger
3029
import kotlin.LazyThreadSafetyMode.NONE
@@ -178,9 +177,6 @@ internal class PixelCopyStrategy(
178177
mainLooperHandler.handler,
179178
)
180179
} catch (e: Throwable) {
181-
// PixelCopy goes through the device's graphics stack, so we can't know what it throws. The
182-
// frame is skipped, and the frame gate is released for the next one.
183-
ExceptionUtils.rethrowIfFatal(e)
184180
options.logger.log(WARNING, "Failed to capture replay recording", e)
185181
unstableCaptures.set(0)
186182
lastCaptureSuccessful.set(false)
@@ -298,9 +294,6 @@ internal class PixelCopyStrategy(
298294
// double-recycle if the recycle paths above already ran.
299295
svBitmap = null
300296
} catch (e: Throwable) {
301-
// PixelCopy goes through the device's graphics stack, so we can't know what it throws.
302-
// This SurfaceView is left out of the frame.
303-
ExceptionUtils.rethrowIfFatal(e)
304297
options.logger.log(WARNING, "Failed to capture SurfaceView", e)
305298
svBitmap?.recycle()
306299
onCaptureComplete()

‎sentry-apollo-3/src/main/java/io/sentry/apollo3/SentryApollo3HttpInterceptor.kt‎

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import io.sentry.protocol.Mechanism
3030
import io.sentry.protocol.Request
3131
import io.sentry.protocol.Response
3232
import io.sentry.util.CookieUtils
33-
import io.sentry.util.ExceptionUtils
3433
import io.sentry.util.GraphqlUtils
3534
import io.sentry.util.HttpUtils
3635
import io.sentry.util.IntegrationUtils.addIntegrationToSdkVersion
@@ -230,9 +229,6 @@ constructor(
230229
span.spanContext.sampled = false
231230
}
232231
} catch (e: Throwable) {
233-
// beforeSpan is the user's callback, so we can't know what it throws. The span is
234-
// dropped, as if the callback had returned null.
235-
ExceptionUtils.rethrowIfFatal(e)
236232
span.spanContext.sampled = false
237233
if (wasSampled) {
238234
scopes.options.clientReportRecorder.recordLostEvent(
@@ -438,9 +434,6 @@ constructor(
438434
it.writeTo(buffer)
439435
data = GraphqlUtils.filterRequestBody(buffer.readUtf8(), scopes.options)
440436
} catch (e: Throwable) {
441-
// writeTo runs the app's own request body code, so we can't know what it throws.
442-
// The event is sent without the request body.
443-
ExceptionUtils.rethrowIfFatal(e)
444437
scopes.options.logger.log(SentryLevel.ERROR, "Error reading the request body.", e)
445438
// continue because the response body alone can already give some insights
446439
} finally {
@@ -473,9 +466,6 @@ constructor(
473466

474467
scopes.captureEvent(event, hint)
475468
} catch (e: Throwable) {
476-
// This runs inside the app's GraphQL request, which must not fail because reporting it
477-
// failed. The failed-request event is not sent.
478-
ExceptionUtils.rethrowIfFatal(e)
479469
scopes.options.logger.log(SentryLevel.ERROR, "Error capturing the GraphQL error.", e)
480470
}
481471
}
@@ -485,10 +475,6 @@ constructor(
485475
/**
486476
* Mutates span before being added.
487477
*
488-
* If this throws, the span is dropped, as if this had returned null. Fatal errors such as
489-
* [OutOfMemoryError] are rethrown instead. The failure is only logged at ERROR level through
490-
* [io.sentry.SentryOptions.getLogger], which by default prints only when debug is enabled.
491-
*
492478
* @param span the span to mutate or drop
493479
* @param request the Apollo request object
494480
* @param response the Apollo response object

‎sentry-apollo-4/src/main/java/io/sentry/apollo4/SentryApollo4HttpInterceptor.kt‎

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import io.sentry.protocol.Mechanism
2828
import io.sentry.protocol.Request
2929
import io.sentry.protocol.Response
3030
import io.sentry.util.CookieUtils
31-
import io.sentry.util.ExceptionUtils
3231
import io.sentry.util.GraphqlUtils
3332
import io.sentry.util.HttpUtils
3433
import io.sentry.util.IntegrationUtils.addIntegrationToSdkVersion
@@ -229,9 +228,6 @@ constructor(
229228
span.spanContext.sampled = false
230229
}
231230
} catch (e: Throwable) {
232-
// beforeSpan is the user's callback, so we can't know what it throws. The span is
233-
// dropped, as if the callback had returned null.
234-
ExceptionUtils.rethrowIfFatal(e)
235231
span.spanContext.sampled = false
236232
if (wasSampled) {
237233
scopes.options.clientReportRecorder.recordLostEvent(
@@ -437,9 +433,6 @@ constructor(
437433
it.writeTo(buffer)
438434
data = GraphqlUtils.filterRequestBody(buffer.readUtf8(), scopes.options)
439435
} catch (e: Throwable) {
440-
// writeTo runs the app's own request body code, so we can't know what it throws.
441-
// The event is sent without the request body.
442-
ExceptionUtils.rethrowIfFatal(e)
443436
scopes.options.logger.log(SentryLevel.ERROR, "Error reading the request body.", e)
444437
// continue because the response body alone can already give some insights
445438
} finally {
@@ -472,9 +465,6 @@ constructor(
472465

473466
scopes.captureEvent(event, hint)
474467
} catch (e: Throwable) {
475-
// This runs inside the app's GraphQL request, which must not fail because reporting it
476-
// failed. The failed-request event is not sent.
477-
ExceptionUtils.rethrowIfFatal(e)
478468
scopes.options.logger.log(SentryLevel.ERROR, "Error capturing the GraphQL error.", e)
479469
}
480470
}
@@ -484,10 +474,6 @@ constructor(
484474
/**
485475
* Mutates span before being added.
486476
*
487-
* If this throws, the span is dropped, as if this had returned null. Fatal errors such as
488-
* [OutOfMemoryError] are rethrown instead. The failure is only logged at ERROR level through
489-
* [io.sentry.SentryOptions.getLogger], which by default prints only when debug is enabled.
490-
*
491477
* @param span the span to mutate or drop
492478
* @param request the Apollo request object
493479
* @param response the Apollo response object

‎sentry-logback/src/main/java/io/sentry/logback/SentryAppender.java‎

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import io.sentry.protocol.Message;
3030
import io.sentry.protocol.SdkVersion;
3131
import io.sentry.util.CollectionUtils;
32-
import io.sentry.util.ExceptionUtils;
3332
import io.sentry.util.LoggerPropertiesUtil;
3433
import java.nio.charset.StandardCharsets;
3534
import java.util.Arrays;
@@ -214,9 +213,8 @@ private String formatted(@NotNull ILoggingEvent loggingEvent) {
214213
try {
215214
return new String(encoder.encode(loggingEvent), StandardCharsets.UTF_8);
216215
} catch (final Throwable t) {
217-
// The encoder is the app's own, possibly misconfigured, so we can't know what it throws.
218-
// The event falls back to the default formatted message.
219-
ExceptionUtils.rethrowIfFatal(t);
216+
// catch exceptions from possibly incorrectly configured encoder
217+
// and fallback to default formatted message
220218
addWarn("Failed to encode logging event", t);
221219
}
222220
}
@@ -349,16 +347,6 @@ void setTransportFactory(final @Nullable ITransportFactory transportFactory) {
349347
this.transportFactory = transportFactory;
350348
}
351349

352-
/**
353-
* Sets the encoder that formats the message sent to Sentry.
354-
*
355-
* <p>If the encoder throws, the logging event's formatted message is sent instead. Fatal errors
356-
* such as {@link OutOfMemoryError} are rethrown. The failure is reported as a warning to
357-
* logback's status manager, which you can see with {@code <configuration debug="true">} or a
358-
* status listener.
359-
*
360-
* @param encoder the encoder
361-
*/
362350
public void setEncoder(Encoder<ILoggingEvent> encoder) {
363351
this.encoder = encoder;
364352
}

0 commit comments

Comments
 (0)