@@ -25,7 +25,7 @@ public class TombstoneParser implements Closeable {
2525 private final InputStream tombstoneStream ;
2626 private final Map <String , String > excTypeValueMap = new HashMap <>();
2727
28- public TombstoneParser (InputStream tombstoneStream ) {
28+ public TombstoneParser (@ NonNull final InputStream tombstoneStream ) {
2929 this .tombstoneStream = tombstoneStream ;
3030
3131 // keep the current signal type -> value mapping for compatibility
@@ -37,10 +37,13 @@ public TombstoneParser(InputStream tombstoneStream) {
3737 excTypeValueMap .put ("SIGSEGV" , "Segfault" );
3838 }
3939
40+ @ NonNull
4041 public SentryEvent parse () throws IOException {
41- TombstoneProtos .Tombstone tombstone = TombstoneProtos .Tombstone .parseFrom (tombstoneStream );
42+ @ NonNull
43+ final TombstoneProtos .Tombstone tombstone =
44+ TombstoneProtos .Tombstone .parseFrom (tombstoneStream );
4245
43- SentryEvent event = new SentryEvent ();
46+ final SentryEvent event = new SentryEvent ();
4447 event .setLevel (SentryLevel .FATAL );
4548
4649 // must use the "native" platform because otherwise the stack-trace wouldn't be correctly parsed
@@ -50,24 +53,25 @@ public SentryEvent parse() throws IOException {
5053 event .setDebugMeta (createDebugMeta (tombstone ));
5154 event .setExceptions (createException (tombstone ));
5255 assert event .getExceptions () != null ;
56+ assert event .getExceptions ().size () == 1 ;
5357 event .setThreads (createThreads (tombstone , event .getExceptions ().get (0 )));
5458
5559 return event ;
5660 }
5761
5862 @ NonNull
5963 private List <SentryThread > createThreads (
60- TombstoneProtos .Tombstone tombstone , SentryException exc ) {
61- List <SentryThread > threads = new ArrayList <>();
64+ @ NonNull final TombstoneProtos .Tombstone tombstone , @ NonNull final SentryException exc ) {
65+ final List <SentryThread > threads = new ArrayList <>();
6266 for (Map .Entry <Integer , TombstoneProtos .Thread > threadEntry :
6367 tombstone .getThreadsMap ().entrySet ()) {
64- TombstoneProtos .Thread threadEntryValue = threadEntry .getValue ();
68+ final TombstoneProtos .Thread threadEntryValue = threadEntry .getValue ();
6569
66- SentryThread thread = new SentryThread ();
70+ final SentryThread thread = new SentryThread ();
6771 thread .setId (Long .valueOf (threadEntry .getKey ()));
6872 thread .setName (threadEntryValue .getName ());
6973
70- SentryStackTrace stacktrace = createStackTrace (threadEntryValue );
74+ final SentryStackTrace stacktrace = createStackTrace (threadEntryValue );
7175 thread .setStacktrace (stacktrace );
7276 if (tombstone .getTid () == threadEntryValue .getId ()) {
7377 thread .setCrashed (true );
@@ -82,26 +86,26 @@ private List<SentryThread> createThreads(
8286 }
8387
8488 @ NonNull
85- private static SentryStackTrace createStackTrace (TombstoneProtos .Thread thread ) {
86- List <SentryStackFrame > frames = new ArrayList <>();
89+ private static SentryStackTrace createStackTrace (@ NonNull final TombstoneProtos .Thread thread ) {
90+ final List <SentryStackFrame > frames = new ArrayList <>();
8791
8892 for (TombstoneProtos .BacktraceFrame frame : thread .getCurrentBacktraceList ()) {
89- SentryStackFrame stackFrame = new SentryStackFrame ();
93+ final SentryStackFrame stackFrame = new SentryStackFrame ();
9094 stackFrame .setPackage (frame .getFileName ());
9195 stackFrame .setFunction (frame .getFunctionName ());
9296 stackFrame .setInstructionAddr (String .format ("0x%x" , frame .getPc ()));
9397 frames .add (0 , stackFrame );
9498 }
9599
96- SentryStackTrace stacktrace = new SentryStackTrace ();
100+ final SentryStackTrace stacktrace = new SentryStackTrace ();
97101 stacktrace .setFrames (frames );
98102
99103 // `libunwindstack` used for tombstones already applies instruction address adjustment:
100104 // https://android.googlesource.com/platform/system/unwinding/+/refs/heads/main/libunwindstack/Regs.cpp#175
101105 // prevent "processing" from doing it again.
102106 stacktrace .setInstructionAddressAdjustment ("none" );
103107
104- Map <String , String > registers = new HashMap <>();
108+ final Map <String , String > registers = new HashMap <>();
105109 for (TombstoneProtos .Register register : thread .getRegistersList ()) {
106110 registers .put (register .getName (), String .format ("0x%x" , register .getU64 ()));
107111 }
@@ -111,27 +115,28 @@ private static SentryStackTrace createStackTrace(TombstoneProtos.Thread thread)
111115 }
112116
113117 @ NonNull
114- private List <SentryException > createException (TombstoneProtos .Tombstone tombstone ) {
115- SentryException exception = new SentryException ();
118+ private List <SentryException > createException (@ NonNull TombstoneProtos .Tombstone tombstone ) {
119+ final SentryException exception = new SentryException ();
116120
117121 if (tombstone .hasSignalInfo ()) {
118- TombstoneProtos .Signal signalInfo = tombstone .getSignalInfo ();
122+ final TombstoneProtos .Signal signalInfo = tombstone .getSignalInfo ();
119123 exception .setType (signalInfo .getName ());
120124 exception .setValue (excTypeValueMap .get (signalInfo .getName ()));
121125 exception .setMechanism (createMechanismFromSignalInfo (signalInfo ));
122126 }
123127
124128 exception .setThreadId ((long ) tombstone .getTid ());
125- List <SentryException > exceptions = new ArrayList <>(1 );
129+ final List <SentryException > exceptions = new ArrayList <>(1 );
126130 exceptions .add (exception );
127131
128132 return exceptions ;
129133 }
130134
131135 @ NonNull
132- private static Mechanism createMechanismFromSignalInfo (TombstoneProtos .Signal signalInfo ) {
136+ private static Mechanism createMechanismFromSignalInfo (
137+ @ NonNull final TombstoneProtos .Signal signalInfo ) {
133138
134- Mechanism mechanism = new Mechanism ();
139+ final Mechanism mechanism = new Mechanism ();
135140 // this follows the current processing triggers strictly, changing any of these
136141 // alters grouping and name (long-term we might want to have a tombstone mechanism)
137142 // TODO: if we align this with ANRv2 this would be overwritten in a BackfillingEventProcessor as
@@ -144,7 +149,7 @@ private static Mechanism createMechanismFromSignalInfo(TombstoneProtos.Signal si
144149 mechanism .setHandled (false );
145150 mechanism .setSynthetic (true );
146151
147- Map <String , Object > meta = new HashMap <>();
152+ final Map <String , Object > meta = new HashMap <>();
148153 meta .put ("number" , signalInfo .getNumber ());
149154 meta .put ("name" , signalInfo .getName ());
150155 meta .put ("code" , signalInfo .getCode ());
@@ -155,9 +160,9 @@ private static Mechanism createMechanismFromSignalInfo(TombstoneProtos.Signal si
155160 }
156161
157162 @ NonNull
158- private Message constructMessage (TombstoneProtos .Tombstone tombstone ) {
159- Message message = new Message ();
160- TombstoneProtos .Signal signalInfo = tombstone .getSignalInfo ();
163+ private Message constructMessage (@ NonNull final TombstoneProtos .Tombstone tombstone ) {
164+ final Message message = new Message ();
165+ final TombstoneProtos .Signal signalInfo = tombstone .getSignalInfo ();
161166
162167 // reproduce the message `debuggerd` would use to dump the stack trace in logcat
163168 message .setFormatted (
@@ -174,8 +179,8 @@ private Message constructMessage(TombstoneProtos.Tombstone tombstone) {
174179 return message ;
175180 }
176181
177- private DebugMeta createDebugMeta (TombstoneProtos .Tombstone tombstone ) {
178- List <DebugImage > images = new ArrayList <>();
182+ private DebugMeta createDebugMeta (@ NonNull final TombstoneProtos .Tombstone tombstone ) {
183+ final List <DebugImage > images = new ArrayList <>();
179184
180185 for (TombstoneProtos .MemoryMapping module : tombstone .getMemoryMappingsList ()) {
181186 // exclude anonymous and non-executable maps
@@ -184,7 +189,7 @@ private DebugMeta createDebugMeta(TombstoneProtos.Tombstone tombstone) {
184189 || !module .getExecute ()) {
185190 continue ;
186191 }
187- DebugImage image = new DebugImage ();
192+ final DebugImage image = new DebugImage ();
188193 image .setCodeId (module .getBuildId ());
189194 image .setCodeFile (module .getMappingName ());
190195 image .setDebugId (module .getBuildId ());
@@ -195,7 +200,7 @@ private DebugMeta createDebugMeta(TombstoneProtos.Tombstone tombstone) {
195200 images .add (image );
196201 }
197202
198- DebugMeta debugMeta = new DebugMeta ();
203+ final DebugMeta debugMeta = new DebugMeta ();
199204 debugMeta .setImages (images );
200205
201206 return debugMeta ;
0 commit comments