Skip to content

Commit 36fa71e

Browse files
committed
refactor instructionAddressAdjustment from String to enum
1 parent 5bd19b0 commit 36fa71e

File tree

4 files changed

+55
-10
lines changed

4 files changed

+55
-10
lines changed

sentry-android-core/src/main/java/io/sentry/android/core/internal/tombstone/TombstoneParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ private static SentryStackTrace createStackTrace(@NonNull final TombstoneProtos.
104104
// `libunwindstack` used for tombstones already applies instruction address adjustment:
105105
// https://android.googlesource.com/platform/system/unwinding/+/refs/heads/main/libunwindstack/Regs.cpp#175
106106
// prevent "processing" from doing it again.
107-
stacktrace.setInstructionAddressAdjustment("none");
107+
stacktrace.setInstructionAddressAdjustment(SentryStackTrace.InstructionAddressAdjustment.NONE);
108108

109109
final Map<String, String> registers = new HashMap<>();
110110
for (TombstoneProtos.Register register : thread.getRegistersList()) {

sentry/api/sentry.api

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6233,13 +6233,13 @@ public final class io/sentry/protocol/SentryStackTrace : io/sentry/JsonSerializa
62336233
public fun <init> ()V
62346234
public fun <init> (Ljava/util/List;)V
62356235
public fun getFrames ()Ljava/util/List;
6236-
public fun getInstructionAddressAdjustment ()Ljava/lang/String;
6236+
public fun getInstructionAddressAdjustment ()Lio/sentry/protocol/SentryStackTrace$InstructionAddressAdjustment;
62376237
public fun getRegisters ()Ljava/util/Map;
62386238
public fun getSnapshot ()Ljava/lang/Boolean;
62396239
public fun getUnknown ()Ljava/util/Map;
62406240
public fun serialize (Lio/sentry/ObjectWriter;Lio/sentry/ILogger;)V
62416241
public fun setFrames (Ljava/util/List;)V
6242-
public fun setInstructionAddressAdjustment (Ljava/lang/String;)V
6242+
public fun setInstructionAddressAdjustment (Lio/sentry/protocol/SentryStackTrace$InstructionAddressAdjustment;)V
62436243
public fun setRegisters (Ljava/util/Map;)V
62446244
public fun setSnapshot (Ljava/lang/Boolean;)V
62456245
public fun setUnknown (Ljava/util/Map;)V
@@ -6251,6 +6251,22 @@ public final class io/sentry/protocol/SentryStackTrace$Deserializer : io/sentry/
62516251
public synthetic fun deserialize (Lio/sentry/ObjectReader;Lio/sentry/ILogger;)Ljava/lang/Object;
62526252
}
62536253

6254+
public final class io/sentry/protocol/SentryStackTrace$InstructionAddressAdjustment : java/lang/Enum, io/sentry/JsonSerializable {
6255+
public static final field ALL Lio/sentry/protocol/SentryStackTrace$InstructionAddressAdjustment;
6256+
public static final field ALL_BUT_FIRST Lio/sentry/protocol/SentryStackTrace$InstructionAddressAdjustment;
6257+
public static final field AUTO Lio/sentry/protocol/SentryStackTrace$InstructionAddressAdjustment;
6258+
public static final field NONE Lio/sentry/protocol/SentryStackTrace$InstructionAddressAdjustment;
6259+
public fun serialize (Lio/sentry/ObjectWriter;Lio/sentry/ILogger;)V
6260+
public static fun valueOf (Ljava/lang/String;)Lio/sentry/protocol/SentryStackTrace$InstructionAddressAdjustment;
6261+
public static fun values ()[Lio/sentry/protocol/SentryStackTrace$InstructionAddressAdjustment;
6262+
}
6263+
6264+
public final class io/sentry/protocol/SentryStackTrace$InstructionAddressAdjustment$Deserializer : io/sentry/JsonDeserializer {
6265+
public fun <init> ()V
6266+
public fun deserialize (Lio/sentry/ObjectReader;Lio/sentry/ILogger;)Lio/sentry/protocol/SentryStackTrace$InstructionAddressAdjustment;
6267+
public synthetic fun deserialize (Lio/sentry/ObjectReader;Lio/sentry/ILogger;)Ljava/lang/Object;
6268+
}
6269+
62546270
public final class io/sentry/protocol/SentryStackTrace$JsonKeys {
62556271
public static final field FRAMES Ljava/lang/String;
62566272
public static final field INSTRUCTION_ADDRESS_ADJUSTMENT Ljava/lang/String;

sentry/src/main/java/io/sentry/JsonSerializer.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ public JsonSerializer(@NotNull SentryOptions options) {
8787
Device.DeviceOrientation.class, new Device.DeviceOrientation.Deserializer());
8888
deserializersByClass.put(Feedback.class, new Feedback.Deserializer());
8989
deserializersByClass.put(Gpu.class, new Gpu.Deserializer());
90+
deserializersByClass.put(
91+
SentryStackTrace.InstructionAddressAdjustment.class,
92+
new SentryStackTrace.InstructionAddressAdjustment.Deserializer());
9093
deserializersByClass.put(MeasurementValue.class, new MeasurementValue.Deserializer());
9194
deserializersByClass.put(Mechanism.class, new Mechanism.Deserializer());
9295
deserializersByClass.put(Message.class, new Message.Deserializer());

sentry/src/main/java/io/sentry/protocol/SentryStackTrace.java

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import io.sentry.vendor.gson.stream.JsonToken;
1111
import java.io.IOException;
1212
import java.util.List;
13+
import java.util.Locale;
1314
import java.util.Map;
1415
import java.util.concurrent.ConcurrentHashMap;
1516
import 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

Comments
 (0)