@@ -20,21 +20,14 @@ public final class SentryThreadFactory {
2020 /** the SentryStackTraceFactory */
2121 private final @ NotNull SentryStackTraceFactory sentryStackTraceFactory ;
2222
23- /** the SentryOptions. */
24- private final @ NotNull SentryOptions options ;
25-
2623 /**
2724 * ctor SentryThreadFactory that takes a SentryStackTraceFactory
2825 *
2926 * @param sentryStackTraceFactory the SentryStackTraceFactory
30- * @param options the SentryOptions
3127 */
32- public SentryThreadFactory (
33- final @ NotNull SentryStackTraceFactory sentryStackTraceFactory ,
34- final @ NotNull SentryOptions options ) {
28+ public SentryThreadFactory (final @ NotNull SentryStackTraceFactory sentryStackTraceFactory ) {
3529 this .sentryStackTraceFactory =
3630 Objects .requireNonNull (sentryStackTraceFactory , "The SentryStackTraceFactory is required." );
37- this .options = Objects .requireNonNull (options , "The SentryOptions is required" );
3831 }
3932
4033 /**
@@ -44,12 +37,12 @@ public SentryThreadFactory(
4437 * @return a list of SentryThread with a single item or null
4538 */
4639 @ Nullable
47- List <SentryThread > getCurrentThread () {
40+ List <SentryThread > getCurrentThread (final boolean attachStackTrace ) {
4841 final Map <Thread , StackTraceElement []> threads = new HashMap <>();
4942 final Thread currentThread = Thread .currentThread ();
5043 threads .put (currentThread , currentThread .getStackTrace ());
5144
52- return getCurrentThreads (threads , null , false );
45+ return getCurrentThreads (threads , null , false , attachStackTrace );
5346 }
5447
5548 /**
@@ -63,13 +56,18 @@ List<SentryThread> getCurrentThread() {
6356 */
6457 @ Nullable
6558 List <SentryThread > getCurrentThreads (
66- final @ Nullable List <Long > mechanismThreadIds , final boolean ignoreCurrentThread ) {
67- return getCurrentThreads (Thread .getAllStackTraces (), mechanismThreadIds , ignoreCurrentThread );
59+ final @ Nullable List <Long > mechanismThreadIds ,
60+ final boolean ignoreCurrentThread ,
61+ final boolean attachStackTrace ) {
62+ return getCurrentThreads (
63+ Thread .getAllStackTraces (), mechanismThreadIds , ignoreCurrentThread , attachStackTrace );
6864 }
6965
7066 @ Nullable
71- List <SentryThread > getCurrentThreads (final @ Nullable List <Long > mechanismThreadIds ) {
72- return getCurrentThreads (Thread .getAllStackTraces (), mechanismThreadIds , false );
67+ List <SentryThread > getCurrentThreads (
68+ final @ Nullable List <Long > mechanismThreadIds , final boolean attachStackTrace ) {
69+ return getCurrentThreads (
70+ Thread .getAllStackTraces (), mechanismThreadIds , false , attachStackTrace );
7371 }
7472
7573 /**
@@ -87,7 +85,8 @@ List<SentryThread> getCurrentThreads(final @Nullable List<Long> mechanismThreadI
8785 List <SentryThread > getCurrentThreads (
8886 final @ NotNull Map <Thread , StackTraceElement []> threads ,
8987 final @ Nullable List <Long > mechanismThreadIds ,
90- final boolean ignoreCurrentThread ) {
88+ final boolean ignoreCurrentThread ,
89+ final boolean attachStackTrace ) {
9190 List <SentryThread > result = null ;
9291
9392 final Thread currentThread = Thread .currentThread ();
@@ -109,7 +108,7 @@ List<SentryThread> getCurrentThreads(
109108 && mechanismThreadIds .contains (thread .getId ())
110109 && !ignoreCurrentThread );
111110
112- result .add (getSentryThread (crashed , item .getValue (), item .getKey ()));
111+ result .add (getSentryThread (crashed , item .getValue (), item .getKey (), attachStackTrace ));
113112 }
114113 }
115114
@@ -127,7 +126,8 @@ List<SentryThread> getCurrentThreads(
127126 private @ NotNull SentryThread getSentryThread (
128127 final boolean crashed ,
129128 final @ NotNull StackTraceElement [] stackFramesElements ,
130- final @ NotNull Thread thread ) {
129+ final @ NotNull Thread thread ,
130+ final boolean attachStacktrace ) {
131131 final SentryThread sentryThread = new SentryThread ();
132132
133133 sentryThread .setName (thread .getName ());
@@ -137,15 +137,17 @@ List<SentryThread> getCurrentThreads(
137137 sentryThread .setState (thread .getState ().name ());
138138 sentryThread .setCrashed (crashed );
139139
140- final List <SentryStackFrame > frames =
141- sentryStackTraceFactory .getStackFrames (stackFramesElements , false );
140+ if (attachStacktrace ) {
141+ final List <SentryStackFrame > frames =
142+ sentryStackTraceFactory .getStackFrames (stackFramesElements , false );
142143
143- if ( options . isAttachStacktrace () && frames != null && !frames .isEmpty ()) {
144- final SentryStackTrace sentryStackTrace = new SentryStackTrace (frames );
145- // threads are always gotten either via Thread.currentThread() or Thread.getAllStackTraces()
146- sentryStackTrace .setSnapshot (true );
144+ if ( frames != null && !frames .isEmpty ()) {
145+ final SentryStackTrace sentryStackTrace = new SentryStackTrace (frames );
146+ // threads are always gotten either via Thread.currentThread() or Thread.getAllStackTraces()
147+ sentryStackTrace .setSnapshot (true );
147148
148- sentryThread .setStacktrace (sentryStackTrace );
149+ sentryThread .setStacktrace (sentryStackTrace );
150+ }
149151 }
150152
151153 return sentryThread ;
0 commit comments