File tree Expand file tree Collapse file tree
sentry-android-core/src/main/java/io/sentry/android/core Expand file tree Collapse file tree Original file line number Diff line number Diff line change 99import io .sentry .IScopes ;
1010import io .sentry .ISentryLifecycleToken ;
1111import io .sentry .Integration ;
12- import io .sentry .OptionsContainer ;
1312import io .sentry .Sentry ;
1413import io .sentry .SentryLevel ;
1514import io .sentry .SentryOptions ;
@@ -98,7 +97,7 @@ public static void init(
9897 @ NotNull Sentry .OptionsConfiguration <SentryAndroidOptions > configuration ) {
9998 try (final @ NotNull ISentryLifecycleToken ignored = staticLock .acquire ()) {
10099 Sentry .init (
101- OptionsContainer . create ( SentryAndroidOptions . class ),
100+ new SentryAndroidOptionsContainer ( ),
102101 options -> {
103102 final io .sentry .util .LoadClass classLoader = new io .sentry .util .LoadClass ();
104103 final boolean isTimberUpstreamAvailable =
Original file line number Diff line number Diff line change 1+ package io .sentry .android .core ;
2+
3+ import io .sentry .OptionsContainer ;
4+ import org .jetbrains .annotations .NotNull ;
5+
6+ /**
7+ * Direct OptionsContainer for SentryAndroidOptions that avoids reflective
8+ * getDeclaredConstructor().newInstance() on the Android startup path.
9+ */
10+ final class SentryAndroidOptionsContainer extends OptionsContainer <SentryAndroidOptions > {
11+
12+ @ Override
13+ public @ NotNull SentryAndroidOptions createInstance () {
14+ return new SentryAndroidOptions ();
15+ }
16+ }
Original file line number Diff line number Diff line change @@ -2068,7 +2068,8 @@ public abstract interface class io/sentry/ObjectWriter {
20682068 public abstract fun value (Z)Lio/sentry/ObjectWriter;
20692069}
20702070
2071- public final class io/sentry/OptionsContainer {
2071+ public class io/sentry/OptionsContainer {
2072+ protected fun <init> ()V
20722073 public static fun create (Ljava/lang/Class;)Lio/sentry/OptionsContainer;
20732074 public fun createInstance ()Ljava/lang/Object;
20742075}
Original file line number Diff line number Diff line change 11package io .sentry ;
22
3+ import com .jakewharton .nopen .annotation .Open ;
4+ import io .sentry .util .Objects ;
35import java .lang .reflect .InvocationTargetException ;
46import org .jetbrains .annotations .ApiStatus ;
57import org .jetbrains .annotations .NotNull ;
8+ import org .jetbrains .annotations .Nullable ;
69
710@ ApiStatus .Internal
8- public final class OptionsContainer <T > {
11+ @ Open
12+ public class OptionsContainer <T > {
913
1014 public @ NotNull static <T > OptionsContainer <T > create (final @ NotNull Class <T > clazz ) {
1115 return new OptionsContainer <>(clazz );
1216 }
1317
14- private final @ NotNull Class <T > clazz ;
18+ private final @ Nullable Class <T > clazz ;
1519
1620 private OptionsContainer (final @ NotNull Class <T > clazz ) {
1721 super ();
1822 this .clazz = clazz ;
1923 }
2024
25+ /** Constructor for subclasses that create the instance directly without reflection. */
26+ protected OptionsContainer () {
27+ super ();
28+ this .clazz = null ;
29+ }
30+
2131 public @ NotNull T createInstance ()
2232 throws InstantiationException ,
2333 IllegalAccessException ,
2434 NoSuchMethodException ,
2535 InvocationTargetException {
26- return clazz .getDeclaredConstructor ().newInstance ();
36+ return Objects .requireNonNull (clazz , "OptionsContainer clazz is required" )
37+ .getDeclaredConstructor ()
38+ .newInstance ();
2739 }
2840}
You can’t perform that action at this time.
0 commit comments