diff --git a/sentry-android-core/src/main/java/io/sentry/android/core/DefaultAndroidEventProcessor.java b/sentry-android-core/src/main/java/io/sentry/android/core/DefaultAndroidEventProcessor.java index b6fb245c11d..c2139d9dcbe 100644 --- a/sentry-android-core/src/main/java/io/sentry/android/core/DefaultAndroidEventProcessor.java +++ b/sentry-android-core/src/main/java/io/sentry/android/core/DefaultAndroidEventProcessor.java @@ -232,59 +232,39 @@ private void mergeOS(final @NotNull SentryBaseEvent event) { } private void setDevice(final @NotNull SentryLogEvent event) { - try { - event.setAttribute( - "device.brand", - new SentryLogEventAttributeValue(SentryAttributeType.STRING, Build.BRAND)); - event.setAttribute( - "device.model", - new SentryLogEventAttributeValue(SentryAttributeType.STRING, Build.MODEL)); - event.setAttribute( - "device.family", - new SentryLogEventAttributeValue(SentryAttributeType.STRING, deviceFamily.getValue())); - } catch (Throwable e) { - options.getLogger().log(SentryLevel.ERROR, "Failed to retrieve device info", e); - } + event.setAttribute( + "device.brand", new SentryLogEventAttributeValue(SentryAttributeType.STRING, Build.BRAND)); + event.setAttribute( + "device.model", new SentryLogEventAttributeValue(SentryAttributeType.STRING, Build.MODEL)); + event.setAttribute( + "device.family", + new SentryLogEventAttributeValue(SentryAttributeType.STRING, deviceFamily.getValue())); } private void setOs(final @NotNull SentryLogEvent event) { - try { - event.setAttribute( - "os.name", new SentryLogEventAttributeValue(SentryAttributeType.STRING, "Android")); - event.setAttribute( - "os.version", - new SentryLogEventAttributeValue(SentryAttributeType.STRING, Build.VERSION.RELEASE)); - } catch (Throwable e) { - options.getLogger().log(SentryLevel.ERROR, "Failed to retrieve os system", e); - } + event.setAttribute( + "os.name", new SentryLogEventAttributeValue(SentryAttributeType.STRING, "Android")); + event.setAttribute( + "os.version", + new SentryLogEventAttributeValue(SentryAttributeType.STRING, Build.VERSION.RELEASE)); } private void setDevice(final @NotNull SentryMetricsEvent event) { - try { - event.setAttribute( - "device.brand", - new SentryLogEventAttributeValue(SentryAttributeType.STRING, Build.BRAND)); - event.setAttribute( - "device.model", - new SentryLogEventAttributeValue(SentryAttributeType.STRING, Build.MODEL)); - event.setAttribute( - "device.family", - new SentryLogEventAttributeValue(SentryAttributeType.STRING, deviceFamily.getValue())); - } catch (Throwable e) { - options.getLogger().log(SentryLevel.ERROR, "Failed to retrieve device info", e); - } + event.setAttribute( + "device.brand", new SentryLogEventAttributeValue(SentryAttributeType.STRING, Build.BRAND)); + event.setAttribute( + "device.model", new SentryLogEventAttributeValue(SentryAttributeType.STRING, Build.MODEL)); + event.setAttribute( + "device.family", + new SentryLogEventAttributeValue(SentryAttributeType.STRING, deviceFamily.getValue())); } private void setOs(final @NotNull SentryMetricsEvent event) { - try { - event.setAttribute( - "os.name", new SentryLogEventAttributeValue(SentryAttributeType.STRING, "Android")); - event.setAttribute( - "os.version", - new SentryLogEventAttributeValue(SentryAttributeType.STRING, Build.VERSION.RELEASE)); - } catch (Throwable e) { - options.getLogger().log(SentryLevel.ERROR, "Failed to retrieve os system", e); - } + event.setAttribute( + "os.name", new SentryLogEventAttributeValue(SentryAttributeType.STRING, "Android")); + event.setAttribute( + "os.version", + new SentryLogEventAttributeValue(SentryAttributeType.STRING, Build.VERSION.RELEASE)); } // Data to be applied to events that was created in the running process diff --git a/sentry-android-core/src/main/java/io/sentry/android/core/DeviceInfoUtil.java b/sentry-android-core/src/main/java/io/sentry/android/core/DeviceInfoUtil.java index 3cc0b3c67f5..19113768ef3 100644 --- a/sentry-android-core/src/main/java/io/sentry/android/core/DeviceInfoUtil.java +++ b/sentry-android-core/src/main/java/io/sentry/android/core/DeviceInfoUtil.java @@ -369,16 +369,10 @@ private Device.DeviceOrientation getOrientation() { * * @return the total amount of internal storage, in bytes */ - @Nullable - private Long getTotalInternalStorage(final @NotNull StatFs stat) { - try { - long blockSize = stat.getBlockSizeLong(); - long totalBlocks = stat.getBlockCountLong(); - return totalBlocks * blockSize; - } catch (Throwable e) { - options.getLogger().log(SentryLevel.ERROR, "Error getting total internal storage amount.", e); - return null; - } + private long getTotalInternalStorage(final @NotNull StatFs stat) { + long blockSize = stat.getBlockSizeLong(); + long totalBlocks = stat.getBlockCountLong(); + return totalBlocks * blockSize; } /** @@ -386,18 +380,10 @@ private Long getTotalInternalStorage(final @NotNull StatFs stat) { * * @return the unused amount of internal storage, in bytes */ - @Nullable - private Long getUnusedInternalStorage(final @NotNull StatFs stat) { - try { - long blockSize = stat.getBlockSizeLong(); - long availableBlocks = stat.getAvailableBlocksLong(); - return availableBlocks * blockSize; - } catch (Throwable e) { - options - .getLogger() - .log(SentryLevel.ERROR, "Error getting unused internal storage amount.", e); - return null; - } + private long getUnusedInternalStorage(final @NotNull StatFs stat) { + long blockSize = stat.getBlockSizeLong(); + long availableBlocks = stat.getAvailableBlocksLong(); + return availableBlocks * blockSize; } @Nullable @@ -449,16 +435,10 @@ private File getExternalStorageDep(final @Nullable File internalStorage) { * @return the total amount of external storage, in bytes, or null if no external storage is * mounted */ - @Nullable - private Long getTotalExternalStorage(final @NotNull StatFs stat) { - try { - final long blockSize = stat.getBlockSizeLong(); - final long totalBlocks = stat.getBlockCountLong(); - return totalBlocks * blockSize; - } catch (Throwable e) { - options.getLogger().log(SentryLevel.ERROR, "Error getting total external storage amount.", e); - return null; - } + private long getTotalExternalStorage(final @NotNull StatFs stat) { + final long blockSize = stat.getBlockSizeLong(); + final long totalBlocks = stat.getBlockCountLong(); + return totalBlocks * blockSize; } /** @@ -467,18 +447,10 @@ private Long getTotalExternalStorage(final @NotNull StatFs stat) { * @return the unused amount of external storage, in bytes, or null if no external storage is * mounted */ - @Nullable - private Long getUnusedExternalStorage(final @NotNull StatFs stat) { - try { - final long blockSize = stat.getBlockSizeLong(); - final long availableBlocks = stat.getAvailableBlocksLong(); - return availableBlocks * blockSize; - } catch (Throwable e) { - options - .getLogger() - .log(SentryLevel.ERROR, "Error getting unused external storage amount.", e); - return null; - } + private long getUnusedExternalStorage(final @NotNull StatFs stat) { + final long blockSize = stat.getBlockSizeLong(); + final long availableBlocks = stat.getAvailableBlocksLong(); + return availableBlocks * blockSize; } @Nullable diff --git a/sentry-jdbc/src/main/java/io/sentry/jdbc/DatabaseUtils.java b/sentry-jdbc/src/main/java/io/sentry/jdbc/DatabaseUtils.java index 4c442d4ae09..6325105205c 100644 --- a/sentry-jdbc/src/main/java/io/sentry/jdbc/DatabaseUtils.java +++ b/sentry-jdbc/src/main/java/io/sentry/jdbc/DatabaseUtils.java @@ -80,17 +80,11 @@ public static DatabaseDetails parse(final @Nullable String databaseConnectionUrl return parseAsUri(dbSystem, urlString); } if ("sqlserver".equalsIgnoreCase(dbSystem)) { - try { - String dbProperty = ";databasename="; - final int index = urlString.indexOf(dbProperty); - if (index >= 0) { - final @NotNull String dbNameAndMaybeMore = - urlString.substring(index + dbProperty.length()); - return new DatabaseDetails( - dbSystem, StringUtils.substringBefore(dbNameAndMaybeMore, ";")); - } - } catch (Throwable t) { - // ignore + String dbProperty = ";databasename="; + final int index = urlString.indexOf(dbProperty); + if (index >= 0) { + final @NotNull String dbNameAndMaybeMore = urlString.substring(index + dbProperty.length()); + return new DatabaseDetails(dbSystem, StringUtils.substringBefore(dbNameAndMaybeMore, ";")); } } if ("oracle".equalsIgnoreCase(dbSystem)) { diff --git a/sentry/src/main/java/io/sentry/Baggage.java b/sentry/src/main/java/io/sentry/Baggage.java index e4777bd063e..64a2c904a91 100644 --- a/sentry/src/main/java/io/sentry/Baggage.java +++ b/sentry/src/main/java/io/sentry/Baggage.java @@ -112,53 +112,46 @@ public static Baggage fromHeader( @Nullable Double sampleRand = null; if (headerValue != null) { - try { - // see https://errorprone.info/bugpattern/StringSplitter for why limit is passed - final String[] keyValueStrings = headerValue.split(",", -1); - for (final String keyValueString : keyValueStrings) { - if (keyValueString.trim().startsWith(SENTRY_BAGGAGE_PREFIX)) { - try { - // As per spec (https://www.w3.org/TR/baggage/#value) - // a value may contain "=" signs, thus we split by the first occurrence - final int separatorIndex = keyValueString.indexOf("="); - final String key = keyValueString.substring(0, separatorIndex).trim(); - final String keyDecoded = decode(key); - final String value = keyValueString.substring(separatorIndex + 1).trim(); - final String valueDecoded = decode(value); - - if (DSCKeys.SAMPLE_RATE.equals(keyDecoded)) { - sampleRate = toDouble(valueDecoded); - } else if (DSCKeys.SAMPLE_RAND.equals(keyDecoded)) { - sampleRand = toDouble(valueDecoded); - } else { - keyValues.put(keyDecoded, valueDecoded); - } - // Without ignoring SAMPLE_RAND here, we'd be freezing baggage that we're transporting - // via OTel span attributes. - // This is done when a transaction is created via Sentry API. - // In that case Baggage is created before the OTel span is created and we put it on - // the span attributes. - // It does however only contain the sample random value as its only value. - // The OTel code then uses it to create a propagation context from it and ends up - // freezing it, - // preventing outgoing requests (to other systems or Sentry) from adding info to - // baggage and only then freeze it. - if (!DSCKeys.SAMPLE_RAND.equalsIgnoreCase(key)) { - shouldFreeze = true; - } - } catch (Throwable e) { - logger.log( - SentryLevel.ERROR, - e, - "Unable to decode baggage key value pair %s", - keyValueString); + // see https://errorprone.info/bugpattern/StringSplitter for why limit is passed + final String[] keyValueStrings = headerValue.split(",", -1); + for (final String keyValueString : keyValueStrings) { + if (keyValueString.trim().startsWith(SENTRY_BAGGAGE_PREFIX)) { + try { + // As per spec (https://www.w3.org/TR/baggage/#value) + // a value may contain "=" signs, thus we split by the first occurrence + final int separatorIndex = keyValueString.indexOf("="); + final String key = keyValueString.substring(0, separatorIndex).trim(); + final String keyDecoded = decode(key); + final String value = keyValueString.substring(separatorIndex + 1).trim(); + final String valueDecoded = decode(value); + + if (DSCKeys.SAMPLE_RATE.equals(keyDecoded)) { + sampleRate = toDouble(valueDecoded); + } else if (DSCKeys.SAMPLE_RAND.equals(keyDecoded)) { + sampleRand = toDouble(valueDecoded); + } else { + keyValues.put(keyDecoded, valueDecoded); + } + // Without ignoring SAMPLE_RAND here, we'd be freezing baggage that we're transporting + // via OTel span attributes. + // This is done when a transaction is created via Sentry API. + // In that case Baggage is created before the OTel span is created and we put it on + // the span attributes. + // It does however only contain the sample random value as its only value. + // The OTel code then uses it to create a propagation context from it and ends up + // freezing it, + // preventing outgoing requests (to other systems or Sentry) from adding info to + // baggage and only then freeze it. + if (!DSCKeys.SAMPLE_RAND.equalsIgnoreCase(key)) { + shouldFreeze = true; } - } else if (includeThirdPartyValues) { - thirdPartyKeyValueStrings.add(keyValueString.trim()); + } catch (Throwable e) { + logger.log( + SentryLevel.ERROR, e, "Unable to decode baggage key value pair %s", keyValueString); } + } else if (includeThirdPartyValues) { + thirdPartyKeyValueStrings.add(keyValueString.trim()); } - } catch (Throwable e) { - logger.log(SentryLevel.ERROR, e, "Unable to decode baggage header %s", headerValue); } } final String thirdPartyHeader = diff --git a/sentry/src/main/java/io/sentry/SendCachedEnvelopeFireAndForgetIntegration.java b/sentry/src/main/java/io/sentry/SendCachedEnvelopeFireAndForgetIntegration.java index b08e140392c..3ba7ab6503a 100644 --- a/sentry/src/main/java/io/sentry/SendCachedEnvelopeFireAndForgetIntegration.java +++ b/sentry/src/main/java/io/sentry/SendCachedEnvelopeFireAndForgetIntegration.java @@ -173,10 +173,6 @@ private void sendCachedEnvelopes( SentryLevel.ERROR, "Failed to call the executor. Cached events will not be sent. Did you call Sentry.close()?", e); - } catch (Throwable e) { - options - .getLogger() - .log(SentryLevel.ERROR, "Failed to call the executor. Cached events will not be sent", e); } } } diff --git a/sentry/src/main/java/io/sentry/util/CheckInUtils.java b/sentry/src/main/java/io/sentry/util/CheckInUtils.java index 7dd4bd486ba..e5beedefc22 100644 --- a/sentry/src/main/java/io/sentry/util/CheckInUtils.java +++ b/sentry/src/main/java/io/sentry/util/CheckInUtils.java @@ -130,12 +130,8 @@ public static boolean isIgnored( } for (final FilterString ignoredSlug : ignoredSlugs) { - try { - if (ignoredSlug.matches(slug)) { - return true; - } - } catch (Throwable t) { - // ignore invalid regex + if (ignoredSlug.matches(slug)) { + return true; } } diff --git a/sentry/src/main/java/io/sentry/util/SpanUtils.java b/sentry/src/main/java/io/sentry/util/SpanUtils.java index d1002a3cc97..3ed4e4d5f04 100644 --- a/sentry/src/main/java/io/sentry/util/SpanUtils.java +++ b/sentry/src/main/java/io/sentry/util/SpanUtils.java @@ -78,13 +78,9 @@ public static boolean isIgnored( } for (final FilterString ignoredOrigin : ignoredOrigins) { - try { - if (ignoredOrigin.matches(origin)) { - ignoredSpanDecisionsCache.put(origin, true); - return true; - } - } catch (Throwable t) { - // ignore invalid regex + if (ignoredOrigin.matches(origin)) { + ignoredSpanDecisionsCache.put(origin, true); + return true; } } diff --git a/sentry/src/main/java/io/sentry/util/StringUtils.java b/sentry/src/main/java/io/sentry/util/StringUtils.java index 02d7d4636a4..edae53197a9 100644 --- a/sentry/src/main/java/io/sentry/util/StringUtils.java +++ b/sentry/src/main/java/io/sentry/util/StringUtils.java @@ -150,8 +150,6 @@ private StringUtils() {} // For specifying wrong message digest algorithms catch (NoSuchAlgorithmException e) { logger.log(SentryLevel.INFO, "SHA-1 isn't available to calculate the hash.", e); - } catch (Throwable e) { - logger.log(SentryLevel.INFO, "string: %s could not calculate its hash", e, str); } return null; } diff --git a/sentry/src/main/java/io/sentry/util/TracingUtils.java b/sentry/src/main/java/io/sentry/util/TracingUtils.java index 8a1aa0ac660..e4f1254d430 100644 --- a/sentry/src/main/java/io/sentry/util/TracingUtils.java +++ b/sentry/src/main/java/io/sentry/util/TracingUtils.java @@ -187,13 +187,8 @@ public static boolean isIgnored( } for (final FilterString ignoredTransaction : ignoredTransactions) { - - try { - if (ignoredTransaction.matches(transactionName)) { - return true; - } - } catch (Throwable t) { - // ignore invalid regex + if (ignoredTransaction.matches(transactionName)) { + return true; } }