Skip to content

Commit b1e7b97

Browse files
committed
fix(init): Perform less allocation/bytecode instructions in Sentry.init
1 parent 9054d65 commit b1e7b97

File tree

6 files changed

+23
-32
lines changed

6 files changed

+23
-32
lines changed

sentry/src/main/java/io/sentry/DuplicateEventDetectionEventProcessor.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package io.sentry;
22

3-
import io.sentry.util.Objects;
43
import java.util.ArrayList;
54
import java.util.Collections;
65
import java.util.List;
@@ -16,7 +15,7 @@ public final class DuplicateEventDetectionEventProcessor implements EventProcess
1615
private final @NotNull SentryOptions options;
1716

1817
public DuplicateEventDetectionEventProcessor(final @NotNull SentryOptions options) {
19-
this.options = Objects.requireNonNull(options, "options are required");
18+
this.options = options;
2019
}
2120

2221
@Override

sentry/src/main/java/io/sentry/MainEventProcessor.java

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import io.sentry.protocol.SentryTransaction;
99
import io.sentry.protocol.User;
1010
import io.sentry.util.HintUtils;
11-
import io.sentry.util.Objects;
1211
import java.io.Closeable;
1312
import java.io.IOException;
1413
import java.util.ArrayList;
@@ -29,7 +28,7 @@ public final class MainEventProcessor implements EventProcessor, Closeable {
2928
private volatile @Nullable HostnameCache hostnameCache = null;
3029

3130
public MainEventProcessor(final @NotNull SentryOptions options) {
32-
this.options = Objects.requireNonNull(options, "The SentryOptions is required.");
31+
this.options = options;
3332

3433
final SentryStackTraceFactory sentryStackTraceFactory =
3534
new SentryStackTraceFactory(this.options);
@@ -38,17 +37,6 @@ public MainEventProcessor(final @NotNull SentryOptions options) {
3837
sentryThreadFactory = new SentryThreadFactory(sentryStackTraceFactory);
3938
}
4039

41-
MainEventProcessor(
42-
final @NotNull SentryOptions options,
43-
final @NotNull SentryThreadFactory sentryThreadFactory,
44-
final @NotNull SentryExceptionFactory sentryExceptionFactory) {
45-
this.options = Objects.requireNonNull(options, "The SentryOptions is required.");
46-
this.sentryThreadFactory =
47-
Objects.requireNonNull(sentryThreadFactory, "The SentryThreadFactory is required.");
48-
this.sentryExceptionFactory =
49-
Objects.requireNonNull(sentryExceptionFactory, "The SentryExceptionFactory is required.");
50-
}
51-
5240
@Override
5341
public @NotNull SentryEvent process(final @NotNull SentryEvent event, final @NotNull Hint hint) {
5442
setCommons(event);

sentry/src/main/java/io/sentry/SentryExceptionFactory.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import io.sentry.protocol.SentryStackFrame;
77
import io.sentry.protocol.SentryStackTrace;
88
import io.sentry.protocol.SentryThread;
9-
import io.sentry.util.Objects;
109
import java.util.ArrayDeque;
1110
import java.util.ArrayList;
1211
import java.util.Deque;
@@ -31,8 +30,7 @@ public final class SentryExceptionFactory {
3130
* @param sentryStackTraceFactory the sentryStackTraceFactory
3231
*/
3332
public SentryExceptionFactory(final @NotNull SentryStackTraceFactory sentryStackTraceFactory) {
34-
this.sentryStackTraceFactory =
35-
Objects.requireNonNull(sentryStackTraceFactory, "The SentryStackTraceFactory is required.");
33+
this.sentryStackTraceFactory = sentryStackTraceFactory;
3634
}
3735

3836
@NotNull

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

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,24 @@ public void activate() {
655655
executorService = new SentryExecutorService(this);
656656
executorService.prewarm();
657657
}
658+
659+
// SpotlightIntegration is loaded via reflection to allow the sentry-spotlight module
660+
// to be excluded from release builds, preventing insecure HTTP URLs from appearing in APKs
661+
try {
662+
final Class<?> clazz = Class.forName("io.sentry.spotlight.SpotlightIntegration");
663+
boolean alreadyRegistered = false;
664+
for (final Integration integration : integrations) {
665+
if (clazz.isInstance(integration)) {
666+
alreadyRegistered = true;
667+
break;
668+
}
669+
}
670+
if (!alreadyRegistered) {
671+
integrations.add((Integration) clazz.getConstructor().newInstance());
672+
}
673+
} catch (Throwable ignored) {
674+
// SpotlightIntegration not available
675+
}
658676
}
659677

660678
/**
@@ -3340,16 +3358,6 @@ private SentryOptions(final boolean empty) {
33403358

33413359
integrations.add(new ShutdownHookIntegration());
33423360

3343-
// SpotlightIntegration is loaded via reflection to allow the sentry-spotlight module
3344-
// to be excluded from release builds, preventing insecure HTTP URLs from appearing in APKs
3345-
try {
3346-
final Class<?> clazz = Class.forName("io.sentry.spotlight.SpotlightIntegration");
3347-
final Integration spotlight = (Integration) clazz.getConstructor().newInstance();
3348-
integrations.add(spotlight);
3349-
} catch (Throwable ignored) {
3350-
// SpotlightIntegration not available
3351-
}
3352-
33533361
eventProcessors.add(new MainEventProcessor(this));
33543362
eventProcessors.add(new DuplicateEventDetectionEventProcessor(this));
33553363

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import io.sentry.protocol.SentryStackFrame;
44
import io.sentry.protocol.SentryStackTrace;
55
import io.sentry.protocol.SentryThread;
6-
import io.sentry.util.Objects;
76
import java.util.ArrayList;
87
import java.util.HashMap;
98
import java.util.List;
@@ -26,8 +25,7 @@ public final class SentryThreadFactory {
2625
* @param sentryStackTraceFactory the SentryStackTraceFactory
2726
*/
2827
public SentryThreadFactory(final @NotNull SentryStackTraceFactory sentryStackTraceFactory) {
29-
this.sentryStackTraceFactory =
30-
Objects.requireNonNull(sentryStackTraceFactory, "The SentryStackTraceFactory is required.");
28+
this.sentryStackTraceFactory = sentryStackTraceFactory;
3129
}
3230

3331
/**

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public UncaughtExceptionHandlerIntegration() {
4444
}
4545

4646
UncaughtExceptionHandlerIntegration(final @NotNull UncaughtExceptionHandler threadAdapter) {
47-
this.threadAdapter = Objects.requireNonNull(threadAdapter, "threadAdapter is required.");
47+
this.threadAdapter = threadAdapter;
4848
}
4949

5050
@Override

0 commit comments

Comments
 (0)