Skip to content

Commit aaa1ef0

Browse files
committed
fix(core): Suppress the new Error Prone and javac 21 findings in the sentry module
1 parent ddae2a9 commit aaa1ef0

20 files changed

Lines changed: 67 additions & 1 deletion

‎sentry/src/main/java/io/sentry/Baggage.java‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,10 @@ public String getThirdPartyHeader() {
257257
return thirdPartyHeader;
258258
}
259259

260+
// TODO Fix for JDK21: ConcurrentHashMap.keySet() compiled against JDK 8+ returns KeySetView,
261+
// which crashes on Android
262+
// < 24.
263+
@SuppressWarnings("JdkObsolete")
260264
public @NotNull String toHeaderString(@Nullable String thirdPartyBaggageHeaderString) {
261265
final StringBuilder sb = new StringBuilder();
262266
String separator = "";
@@ -325,10 +329,14 @@ public String getThirdPartyHeader() {
325329
return sb.toString();
326330
}
327331

332+
// TODO Fix for JDK21: The Charset overload requires Java 10.
333+
@SuppressWarnings("JdkObsolete")
328334
private String encode(final @NotNull String value) throws UnsupportedEncodingException {
329335
return URLEncoder.encode(value, CHARSET).replaceAll("\\+", "%20");
330336
}
331337

338+
// TODO Fix for JDK21: The Charset overload requires Java 10.
339+
@SuppressWarnings("JdkObsolete")
332340
private static String decode(final @NotNull String value) throws UnsupportedEncodingException {
333341
return URLDecoder.decode(value, CHARSET);
334342
}

‎sentry/src/main/java/io/sentry/Breadcrumb.java‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,8 @@ public void setType(@Nullable String type) {
630630
this.type = type;
631631
}
632632

633+
// TODO Fix for JDK21: EMPTY_DATA is a sentinel, so identity comparison is intended.
634+
@SuppressWarnings("ReferenceEquality")
633635
private @NotNull Map<String, @NotNull Object> getOrCreateData() {
634636
Map<String, @NotNull Object> currentData = data;
635637
if (currentData == EMPTY_DATA) {
@@ -691,6 +693,8 @@ public void setData(@Nullable String key, @Nullable Object value) {
691693
*
692694
* @param key the key
693695
*/
696+
// TODO Fix for JDK21: EMPTY_DATA is a sentinel, so identity comparison is intended.
697+
@SuppressWarnings("ReferenceEquality")
694698
public void removeData(@Nullable String key) {
695699
if (key == null) {
696700
return;

‎sentry/src/main/java/io/sentry/DiagnosticLogger.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ public DiagnosticLogger(final @NotNull SentryOptions options, final @Nullable IL
2929
* @param level The SentryLevel to test against.
3030
* @return True if a log message would be recorded for the level. Otherwise false.
3131
*/
32+
// TODO Fix for JDK21: SentryLevel is declared in ascending severity order.
33+
@SuppressWarnings("EnumOrdinal")
3234
@Override
3335
public boolean isEnabled(final @Nullable SentryLevel level) {
3436
final SentryLevel diagLevel = options.getDiagnosticLevel();

‎sentry/src/main/java/io/sentry/MonitorContexts.java‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ public void setTrace(final @NotNull SpanContext traceContext) {
4343

4444
// region json
4545

46+
// TODO Fix for JDK21: ConcurrentHashMap.keySet() compiled against JDK 8+ returns KeySetView,
47+
// which crashes on Android
48+
// < 24.
49+
@SuppressWarnings("JdkObsolete")
4650
@Override
4751
public void serialize(final @NotNull ObjectWriter writer, final @NotNull ILogger logger)
4852
throws IOException {

‎sentry/src/main/java/io/sentry/ReplayRecording.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ public void setUnknown(@Nullable Map<String, Object> unknown) {
102102

103103
public static final class Deserializer implements JsonDeserializer<ReplayRecording> {
104104

105-
@SuppressWarnings("unchecked")
105+
// TODO Fix for JDK21: The rrweb protocol encodes these enums by ordinal.
106+
@SuppressWarnings({"unchecked", "EnumOrdinal"})
106107
@Override
107108
public @NotNull ReplayRecording deserialize(
108109
@NotNull ObjectReader reader, @NotNull ILogger logger) throws Exception {

‎sentry/src/main/java/io/sentry/SentryOptions.java‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@
5858
import org.jetbrains.annotations.TestOnly;
5959

6060
/** Sentry SDK options */
61+
// TODO Fix for JDK21: Constructors call overridable methods; making them final would break the
62+
// public API.
63+
@SuppressWarnings("this-escape")
6164
@Open
6265
public class SentryOptions implements RateLimiterConfig {
6366

‎sentry/src/main/java/io/sentry/SentryThreadFactory.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ List<SentryThread> getCurrentThreads(
7878
* crashed. This is the case for e.g. watchdog threads which are not the one erroring.
7979
* @return a list of SentryThread or null if none
8080
*/
81+
// TODO Fix for JDK21: Identifies the current thread by identity.
82+
@SuppressWarnings("ReferenceEquality")
8183
@TestOnly
8284
@Nullable
8385
List<SentryThread> getCurrentThreads(

‎sentry/src/main/java/io/sentry/SpanContext.java‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
import org.jetbrains.annotations.Nullable;
1717
import org.jetbrains.annotations.TestOnly;
1818

19+
// TODO Fix for JDK21: Constructors call overridable methods; making them final would break the
20+
// public API.
21+
@SuppressWarnings("this-escape")
1922
@Open
2023
public class SpanContext implements JsonUnknown, JsonSerializable {
2124
public static final String TYPE = "trace";

‎sentry/src/main/java/io/sentry/SynchronizedCollection.java‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,14 @@ class SynchronizedCollection<E> implements Collection<E>, Serializable {
5050
private static final long serialVersionUID = 2412805092710877986L;
5151

5252
/** The collection to decorate */
53+
// TODO Fix for JDK21: Serializable only if the decorated collection is, as in Apache Commons
54+
// Collections.
55+
@SuppressWarnings("serial")
5356
private final Collection<E> collection;
5457

5558
/** The object to lock on, needed for List/SortedSet views */
59+
// TODO Fix for JDK21: Not Serializable either; the SDK never serializes these collections.
60+
@SuppressWarnings("serial")
5661
final AutoClosableReentrantLock lock;
5762

5863
/**

‎sentry/src/main/java/io/sentry/UncaughtExceptionHandlerIntegration.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ public UncaughtExceptionHandlerIntegration() {
4747
this.threadAdapter = threadAdapter;
4848
}
4949

50+
// TODO Fix for JDK21: Both integrations must share the same global scope instance.
51+
@SuppressWarnings("ReferenceEquality")
5052
@Override
5153
public final void register(final @NotNull IScopes scopes, final @NotNull SentryOptions options) {
5254
if (registered) {

0 commit comments

Comments
 (0)