Skip to content
Merged
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
- App starts are measured from process start on Android 7.0+ (API 24), and slow and frozen frames are measured per span
- `ActivityFramesTracker` is removed, and the `ActivityLifecycleIntegration` constructor no longer takes it
- Screenshots attached to errors and user feedback now mask all text and images by default. Turn it off with `options.screenshot.setMaskAllText(false)` and `setMaskAllImages(false)`, or the `io.sentry.screenshot.mask-all-text` and `io.sentry.screenshot.mask-all-images` manifest options. Masking needs `sentry-android-replay`, so apps that depend on `sentry-android-core` alone get no screenshot until they add it or turn masking off ([#6437](https://github.com/getsentry/sentry-java/pull/6437))
- Non-recoverable errors such as `OutOfMemoryError` and `StackOverflowError` are no longer swallowed by the SDK. This means that callbacks into app code will now rethrow these exceptions instead of silently swallowing them since they are not recoverable ([#6665](https://github.com/getsentry/sentry-java/pull/6665), [#6666](https://github.com/getsentry/sentry-java/pull/6666), [#6667](https://github.com/getsentry/sentry-java/pull/6667), [#6668](https://github.com/getsentry/sentry-java/pull/6668), [#6669](https://github.com/getsentry/sentry-java/pull/6669), [#6670](https://github.com/getsentry/sentry-java/pull/6670), [#6678](https://github.com/getsentry/sentry-java/pull/6678))

### Features

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import io.sentry.SentryLevel;
import io.sentry.time.Deadline;
import io.sentry.time.MonotonicTicker;
import io.sentry.util.ExceptionUtils;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
Expand Down Expand Up @@ -174,9 +175,16 @@ private boolean isProcessNotResponding() {
if (am != null) {
List<ActivityManager.ProcessErrorStateInfo> processesInErrorState = null;
try {
// It can throw RuntimeException or OutOfMemoryError
processesInErrorState = am.getProcessesInErrorState();
} catch (OutOfMemoryError e) {
// Unparceling the reply, which lists every process in an error state, can fail to
// allocate even when the app itself has memory left, so it's not treated as fatal here
// (#2114). The process is treated as responding normally, so no ANR is reported.
logger.log(SentryLevel.ERROR, "Error getting ActivityManager#getProcessesInErrorState.", e);
} catch (Throwable e) {
// A Binder call into the activity manager, which can rethrow any runtime exception from
// the other side. The process is treated as responding normally, so no ANR is reported.
ExceptionUtils.rethrowIfFatal(e);
logger.log(SentryLevel.ERROR, "Error getting ActivityManager#getProcessesInErrorState.", e);
}
// if list is null, there's no process in ANR state.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import io.sentry.protocol.SentryThread;
import io.sentry.transport.CurrentDateProvider;
import io.sentry.transport.ICurrentDateProvider;
import io.sentry.util.ExceptionUtils;
import io.sentry.util.HintUtils;
import io.sentry.util.Objects;
import java.io.BufferedReader;
Expand Down Expand Up @@ -204,8 +205,12 @@ public void markReported(final long timestamp) {
return new ParseResult(ParseResult.Type.NO_DUMP);
}
dump = NativeEventUtils.readBytes(trace);
} catch (Throwable e) {
options.getLogger().log(SentryLevel.WARNING, "Failed to read ANR thread dump", e);
} catch (Throwable t) {
// getTraceInputStream() is a Binder call into system_server, which can rethrow any runtime
// exception from the other side. As with a missing dump, this ANR is not reported, and the
// remaining exit infos are still processed.
ExceptionUtils.rethrowIfFatal(t);
options.getLogger().log(SentryLevel.WARNING, "Failed to read ANR thread dump", t);
return new ParseResult(ParseResult.Type.NO_DUMP);
}

Expand All @@ -229,6 +234,10 @@ public void markReported(final long timestamp) {
}
return new ParseResult(ParseResult.Type.DUMP, dump, threads, debugImages, artContext);
} catch (Throwable e) {
// The dump is written by ART in a format that changes between Android versions and
// vendors, so we can't know how the parser fails on unexpected input. The ANR is still
// reported, with a message asking to attach the raw dump.
ExceptionUtils.rethrowIfFatal(e);
options.getLogger().log(SentryLevel.WARNING, "Failed to parse ANR thread dump", e);
return new ParseResult(ParseResult.Type.ERROR, dump);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import io.sentry.android.core.internal.util.Debouncer;
import io.sentry.android.core.internal.util.DeviceOrientations;
import io.sentry.protocol.Device;
import io.sentry.util.ExceptionUtils;
import io.sentry.util.Objects;
import java.io.Closeable;
import java.io.IOException;
Expand Down Expand Up @@ -66,6 +67,10 @@ public void register(final @NotNull IScopes scopes, final @NotNull SentryOptions
.log(SentryLevel.DEBUG, "AppComponentsBreadcrumbsIntegration installed.");
addIntegrationToSdkVersion("AppComponentsBreadcrumbs");
} catch (Throwable e) {
// The context may be the app's own subclass, or a ContextImpl that doesn't support
// component callbacks on older versions, so we can't know what this throws. App
// component breadcrumbs are disabled.
ExceptionUtils.rethrowIfFatal(e);
this.options.setEnableAppComponentBreadcrumbs(false);
options.getLogger().log(SentryLevel.INFO, e, "ComponentCallbacks2 is not available.");
}
Expand All @@ -77,12 +82,15 @@ public void close() throws IOException {
try {
// if its a ContextImpl, unregisterComponentCallbacks can't be used
context.unregisterComponentCallbacks(this);
} catch (Throwable ignored) {
// fine, might throw on older versions
} catch (Throwable e) {
// The context may be the app's own subclass, or a ContextImpl that doesn't support
// component callbacks on older versions, so we can't know what this throws. The callbacks
// may stay registered until the process ends.
ExceptionUtils.rethrowIfFatal(e);
if (options != null) {
options
.getLogger()
.log(SentryLevel.DEBUG, ignored, "It was not possible to unregisterComponentCallbacks");
.log(SentryLevel.DEBUG, e, "It was not possible to unregisterComponentCallbacks");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
import io.sentry.protocol.SentryTransaction;
import io.sentry.protocol.User;
import io.sentry.protocol.profiling.SentryProfile;
import io.sentry.util.ExceptionUtils;
import io.sentry.util.HintUtils;
import io.sentry.util.SentryRandom;
import java.io.File;
Expand Down Expand Up @@ -447,6 +448,9 @@ private void setApp(final @NotNull SentryBaseEvent event) {
}
}
} catch (Throwable e) {
// The first DeviceInfoUtil.getInstance call queries the package manager over Binder, which
// can rethrow any runtime exception from the other side. The split APK info is left out.
ExceptionUtils.rethrowIfFatal(e);
options.getLogger().log(SentryLevel.ERROR, "Error getting split apks info.", e);
}

Expand Down Expand Up @@ -716,6 +720,9 @@ private void setSideLoadedInfo(final @NotNull SentryBaseEvent event) {
}
}
} catch (Throwable e) {
// The first DeviceInfoUtil.getInstance call queries the package manager over Binder, which
// can rethrow any runtime exception from the other side. The side-loaded tags are left out.
ExceptionUtils.rethrowIfFatal(e);
options.getLogger().log(SentryLevel.ERROR, "Error getting side loaded info.", e);
}
}
Expand Down Expand Up @@ -975,6 +982,9 @@ private void applyAnrProfile(
options.getLogger().log(SentryLevel.DEBUG, "No ANR profile file found");
}
} catch (Throwable t) {
// The profile file was written by the previous process, possibly while it was being
// killed, so we can't know how reading it fails. The ANR is sent without a profile.
ExceptionUtils.rethrowIfFatal(t);
options.getLogger().log(SentryLevel.INFO, "Could not retrieve ANR profile", t);
} finally {
if (!AnrProfileRotationHelper.deleteLastFile(cacheDir)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import io.sentry.SentryOptions;
import io.sentry.android.core.util.AndroidLazyEvaluator;
import io.sentry.protocol.App;
import io.sentry.util.ExceptionUtils;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
Expand Down Expand Up @@ -104,6 +105,9 @@ private ContextUtils() {}
.getPackageManager()
.getPackageInfo(context.getPackageName(), PackageManager.PackageInfoFlags.of(0));
} catch (Throwable e) {
// A Binder call into the package manager, which can rethrow any runtime exception from
// the other side. The package info is left out.
ExceptionUtils.rethrowIfFatal(e);
return null;
}
});
Expand All @@ -113,6 +117,9 @@ private ContextUtils() {}
try {
return context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
} catch (Throwable e) {
// A Binder call into the package manager, which can rethrow any runtime exception from
// the other side. The package info is left out.
ExceptionUtils.rethrowIfFatal(e);
return null;
}
});
Expand All @@ -131,6 +138,9 @@ private ContextUtils() {}
return context.getString(stringId);
}
} catch (Throwable e) {
// getApplicationLabel is a Binder call into the package manager, and the context may be
// the app's own subclass, so we can't know what this throws. The app name is left out.
ExceptionUtils.rethrowIfFatal(e);
return null;
}
});
Expand All @@ -150,6 +160,9 @@ private ContextUtils() {}
context.getPackageName(),
PackageManager.ApplicationInfoFlags.of(PackageManager.GET_META_DATA));
} catch (Throwable e) {
// A Binder call into the package manager, which can rethrow any runtime exception from
// the other side. The application info is left out.
ExceptionUtils.rethrowIfFatal(e);
return null;
}
});
Expand All @@ -161,6 +174,9 @@ private ContextUtils() {}
.getPackageManager()
.getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA);
} catch (Throwable e) {
// A Binder call into the package manager, which can rethrow any runtime exception from
// the other side. The application info is left out.
ExceptionUtils.rethrowIfFatal(e);
return null;
}
});
Expand Down Expand Up @@ -202,6 +218,9 @@ static PackageInfo getPackageInfo(
return context.getPackageManager().getPackageInfo(context.getPackageName(), flags);
}
} catch (Throwable e) {
// A Binder call into the package manager, which can rethrow any runtime exception from the
// other side. The package info is left out.
ExceptionUtils.rethrowIfFatal(e);
logger.log(SentryLevel.ERROR, "Error getting package info.", e);
return null;
}
Expand Down Expand Up @@ -269,8 +288,10 @@ public static boolean isForegroundImportance() {
new ActivityManager.RunningAppProcessInfo();
ActivityManager.getMyMemoryState(appProcessInfo);
return appProcessInfo.importance == IMPORTANCE_FOREGROUND;
} catch (Throwable ignored) {
// should never happen
} catch (Throwable e) {
// A Binder call into the activity manager, which can rethrow any runtime exception from the
// other side. The process is treated as not in the foreground.
ExceptionUtils.rethrowIfFatal(e);
}
return false;
}
Expand Down Expand Up @@ -299,7 +320,9 @@ public static boolean appIsLibraryForComposePreview(final @NotNull Context conte
}
}
} catch (Throwable t) {
// ignored
// getAppTasks is a Binder call into the activity manager, which can rethrow any runtime
// exception from the other side. The app is treated as not running a Compose Preview.
ExceptionUtils.rethrowIfFatal(t);
}
}
return false;
Expand Down Expand Up @@ -398,6 +421,9 @@ public static boolean appIsLibraryForComposePreview(final @NotNull Context conte
try {
return context.getResources().getDisplayMetrics();
} catch (Throwable e) {
// The context may be the app's own subclass that overrides getResources(), so we can't know
// what it throws. The display metrics are left out.
ExceptionUtils.rethrowIfFatal(e);
logger.log(SentryLevel.ERROR, "Error getting DisplayMetrics.", e);
return null;
}
Expand Down Expand Up @@ -440,6 +466,9 @@ public static boolean appIsLibraryForComposePreview(final @NotNull Context conte
logger.log(SentryLevel.INFO, "Error getting MemoryInfo.");
return null;
} catch (Throwable e) {
// A Binder call into the activity manager, which can rethrow any runtime exception from the
// other side. The memory info is left out.
ExceptionUtils.rethrowIfFatal(e);
logger.log(SentryLevel.ERROR, "Error getting MemoryInfo.", e);
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import io.sentry.protocol.SentryThread;
import io.sentry.protocol.SentryTransaction;
import io.sentry.protocol.User;
import io.sentry.util.ExceptionUtils;
import io.sentry.util.HintUtils;
import io.sentry.util.Objects;
import java.util.Collections;
Expand Down Expand Up @@ -193,6 +194,9 @@ private void setDevice(
.getContexts()
.setDevice(deviceInfoUtil.get().collectDeviceInformation(errorEvent, applyScopeData));
} catch (Throwable e) {
// Collecting the device info makes Binder calls into several system services, which can
// rethrow any runtime exception from the other side. The device context is left out.
ExceptionUtils.rethrowIfFatal(e);
options.getLogger().log(SentryLevel.ERROR, "Failed to retrieve device info", e);
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import io.sentry.android.core.internal.util.RootChecker;
import io.sentry.protocol.Device;
import io.sentry.protocol.OperatingSystem;
import io.sentry.util.ExceptionUtils;
import java.io.File;
import java.util.Calendar;
import java.util.Collections;
Expand Down Expand Up @@ -303,6 +304,9 @@ public static Float getBatteryLevel(

return ((float) level / (float) scale) * percentMultiplier;
} catch (Throwable e) {
// The extras were parceled by system_server and are unparceled on first access, which can
// throw any runtime exception on malformed data. The battery level is left out.
ExceptionUtils.rethrowIfFatal(e);
options.getLogger().log(SentryLevel.ERROR, "Error getting device battery level.", e);
return null;
}
Expand All @@ -321,6 +325,9 @@ public static Boolean isCharging(
return plugged == BatteryManager.BATTERY_PLUGGED_AC
|| plugged == BatteryManager.BATTERY_PLUGGED_USB;
} catch (Throwable e) {
// The extras were parceled by system_server and are unparceled on first access, which can
// throw any runtime exception on malformed data. The charging state is left out.
ExceptionUtils.rethrowIfFatal(e);
options.getLogger().log(SentryLevel.ERROR, "Error getting device charging state.", e);
return null;
}
Expand All @@ -334,6 +341,9 @@ private Float getBatteryTemperature(final @NotNull Intent batteryIntent) {
return ((float) temperature) / 10; // celsius
}
} catch (Throwable e) {
// The extras were parceled by system_server and are unparceled on first access, which can
// throw any runtime exception on malformed data. The temperature is left out.
ExceptionUtils.rethrowIfFatal(e);
options.getLogger().log(SentryLevel.ERROR, "Error getting battery temperature.", e);
}
return null;
Expand All @@ -359,6 +369,9 @@ private Device.DeviceOrientation getOrientation() {
return null;
}
} catch (Throwable e) {
// The context may be the app's own subclass that overrides getResources(), so we can't know
// what it throws. The orientation is left out.
ExceptionUtils.rethrowIfFatal(e);
options.getLogger().log(SentryLevel.ERROR, "Error getting device orientation.", e);
}
return deviceOrientation;
Expand Down Expand Up @@ -394,6 +407,9 @@ private StatFs getExternalStorageStat(final @Nullable File internalStorage) {
return new StatFs(path.getPath());
}
} catch (Throwable e) {
// getExternalFilesDirs asks the storage service over Binder to create the directories, so
// we can't know what it throws. The external storage sizes are left out.
ExceptionUtils.rethrowIfFatal(e);
options.getLogger().log(SentryLevel.INFO, "Not possible to read external files directory");
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import io.sentry.SentryLevel;
import io.sentry.SentryOptions;
import io.sentry.util.AutoClosableReentrantLock;
import io.sentry.util.ExceptionUtils;
import io.sentry.util.FileUtils;
import io.sentry.util.Objects;
import java.io.Closeable;
Expand Down Expand Up @@ -92,7 +93,10 @@ private void startOutboxSender(
options.getLogger().log(SentryLevel.DEBUG, "EnvelopeFileObserverIntegration installed.");
addIntegrationToSdkVersion("EnvelopeFileObserver");
} catch (Throwable e) {
// it could throw eg NoSuchFileException or NullPointerException
// startWatching() sets up inotify through native code, which can throw e.g.
// NoSuchFileException or NullPointerException, so we can't know what it throws. Envelopes
// written to the outbox, e.g. by the NDK, are not picked up while the process runs.
ExceptionUtils.rethrowIfFatal(e);
options
.getLogger()
.log(SentryLevel.ERROR, "Failed to initialize EnvelopeFileObserverIntegration.", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import io.sentry.SentryFeedbackOptions;
import io.sentry.SentryLevel;
import io.sentry.SentryOptions;
import io.sentry.util.ExceptionUtils;
import io.sentry.util.Objects;
import java.io.Closeable;
import java.io.IOException;
Expand Down Expand Up @@ -298,6 +299,9 @@ private void startShakeDetection(final @NotNull Activity activity) {
dialog = dialogFactory.create(active);
dialog.show();
} catch (Throwable e) {
// show() adds a window over Binder and the dialog inflates with the app's theme, so
// we can't know what this throws. No dialog is shown for this shake.
ExceptionUtils.rethrowIfFatal(e);
if (dialog != null) {
onDialogGone(dialog);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import io.sentry.protocol.Device;
import io.sentry.protocol.SentryId;
import io.sentry.protocol.User;
import io.sentry.util.ExceptionUtils;
import io.sentry.util.MapObjectWriter;
import io.sentry.util.TracingUtils;
import java.io.ByteArrayInputStream;
Expand Down Expand Up @@ -139,6 +140,10 @@ public static Map<String, Object> serializeScope(
writer.name("level").value(logger, scope.getLevel());
writer.name("breadcrumbs").value(logger, scope.getBreadcrumbs());
} catch (Throwable e) {
// An entry point for hybrid SDKs. Serializing the scope reaches into the device and package
// manager over Binder and into whatever objects the app put in extras, so we can't know what
// it throws. The caller gets an empty map.
ExceptionUtils.rethrowIfFatal(e);
options.getLogger().log(SentryLevel.ERROR, "Could not serialize scope.", e);
return new HashMap<>();
}
Expand Down Expand Up @@ -204,6 +209,9 @@ public static SentryId captureEnvelope(
new SentryEnvelope(envelope.getHeader(), envelopeItems);
return scopes.captureEnvelope(repackagedEnvelope);
} catch (Throwable t) {
// An entry point for hybrid SDKs, which hand over an envelope we didn't build, so we can't
// know what processing it throws. The envelope is dropped and the caller gets null.
ExceptionUtils.rethrowIfFatal(t);
options.getLogger().log(SentryLevel.ERROR, "Failed to capture envelope", t);
}
return null;
Expand Down
Loading
Loading