1010import io .sentry .vendor .gson .stream .JsonToken ;
1111import java .io .IOException ;
1212import java .util .List ;
13+ import java .util .Locale ;
1314import java .util .Map ;
1415import java .util .concurrent .ConcurrentHashMap ;
1516import org .jetbrains .annotations .NotNull ;
@@ -68,13 +69,12 @@ public final class SentryStackTrace implements JsonUnknown, JsonSerializable {
6869
6970 /**
7071 * This value indicates if, and how, `instruction_addr` values in the stack frames need to be
71- * adjusted before they are symbolicated. TODO: should we make this an enum or is a string value
72- * fine?
72+ * adjusted before they are symbolicated.
7373 *
7474 * @see SentryStackFrame#getInstructionAddr()
7575 * @see SentryStackFrame#setInstructionAddr(String)
7676 */
77- private @ Nullable String instructionAddressAdjustment ;
77+ private @ Nullable InstructionAddressAdjustment instructionAddressAdjustment ;
7878
7979 @ SuppressWarnings ("unused" )
8080 private @ Nullable Map <String , Object > unknown ;
@@ -132,11 +132,12 @@ public void setUnknown(@Nullable Map<String, Object> unknown) {
132132 this .unknown = unknown ;
133133 }
134134
135- public @ Nullable String getInstructionAddressAdjustment () {
135+ public @ Nullable InstructionAddressAdjustment getInstructionAddressAdjustment () {
136136 return instructionAddressAdjustment ;
137137 }
138138
139- public void setInstructionAddressAdjustment (@ Nullable String instructionAddressAdjustment ) {
139+ public void setInstructionAddressAdjustment (
140+ @ Nullable InstructionAddressAdjustment instructionAddressAdjustment ) {
140141 this .instructionAddressAdjustment = instructionAddressAdjustment ;
141142 }
142143
@@ -161,7 +162,9 @@ public void serialize(final @NotNull ObjectWriter writer, final @NotNull ILogger
161162 writer .name (JsonKeys .SNAPSHOT ).value (snapshot );
162163 }
163164 if (instructionAddressAdjustment != null ) {
164- writer .name (JsonKeys .INSTRUCTION_ADDRESS_ADJUSTMENT ).value (instructionAddressAdjustment );
165+ writer
166+ .name (JsonKeys .INSTRUCTION_ADDRESS_ADJUSTMENT )
167+ .value (logger , instructionAddressAdjustment );
165168 }
166169 if (unknown != null ) {
167170 for (String key : unknown .keySet ()) {
@@ -197,7 +200,8 @@ public static final class Deserializer implements JsonDeserializer<SentryStackTr
197200 sentryStackTrace .snapshot = reader .nextBooleanOrNull ();
198201 break ;
199202 case JsonKeys .INSTRUCTION_ADDRESS_ADJUSTMENT :
200- sentryStackTrace .instructionAddressAdjustment = reader .nextStringOrNull ();
203+ sentryStackTrace .instructionAddressAdjustment =
204+ reader .nextOrNull (logger , new InstructionAddressAdjustment .Deserializer ());
201205 break ;
202206 default :
203207 if (unknown == null ) {
@@ -214,4 +218,26 @@ public static final class Deserializer implements JsonDeserializer<SentryStackTr
214218 }
215219
216220 // endregion
221+
222+ public enum InstructionAddressAdjustment implements JsonSerializable {
223+ AUTO ,
224+ ALL ,
225+ ALL_BUT_FIRST ,
226+ NONE ;
227+
228+ @ Override
229+ public void serialize (@ NotNull ObjectWriter writer , @ NotNull ILogger logger )
230+ throws IOException {
231+ writer .value (toString ().toLowerCase (Locale .ROOT ));
232+ }
233+
234+ public static final class Deserializer
235+ implements JsonDeserializer <InstructionAddressAdjustment > {
236+ @ Override
237+ public @ NotNull SentryStackTrace .InstructionAddressAdjustment deserialize (
238+ @ NotNull ObjectReader reader , @ NotNull ILogger logger ) throws Exception {
239+ return InstructionAddressAdjustment .valueOf (reader .nextString ().toUpperCase (Locale .ROOT ));
240+ }
241+ }
242+ }
217243}
0 commit comments