Skip to content

Commit 8549093

Browse files
authored
Revert "Capture trace of error reporting thread and identify with boolean flag" (#88)
Reverts #87
1 parent 45dcdf5 commit 8549093

3 files changed

Lines changed: 17 additions & 79 deletions

File tree

CHANGELOG.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
# Changelog
22

3-
## 3.X.X (TBD)
4-
5-
* Capture trace of error reporting thread and identify with boolean flag
6-
[#87](https://github.com/bugsnag/bugsnag-java/pull/87)
7-
83
## 3.2.0 (2018-07-03)
94

105
This release introduces automatic tracking of sessions, which by

src/main/java/com/bugsnag/ThreadState.java

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.bugsnag;
22

3-
import com.fasterxml.jackson.annotation.JsonInclude;
43
import com.fasterxml.jackson.annotation.JsonProperty;
54

65
import java.util.ArrayList;
@@ -10,11 +9,9 @@
109
import java.util.Map;
1110

1211
class ThreadState {
13-
14-
private final Configuration config;
15-
private final Thread thread;
16-
private final StackTraceElement[] stackTraceElements;
17-
private Boolean errorReportingThread;
12+
private Configuration config;
13+
private Thread thread;
14+
private StackTraceElement[] stackTraceElements;
1815

1916
ThreadState(Configuration config, Thread thread, StackTraceElement[] stackTraceElements) {
2017
this.config = config;
@@ -36,16 +33,19 @@ public int compare(Object first, Object second) {
3633
});
3734

3835
List<ThreadState> threads = new ArrayList<ThreadState>();
36+
for (int i = 0; i < keys.length; i++) {
37+
Thread thread = (Thread) keys[i];
38+
39+
// Don't show the current stacktrace here. It'll point at this method
40+
// rather than at the point they crashed.
41+
if (thread.getId() == crashingThreadId) {
42+
continue;
43+
}
3944

40-
for (Object key : keys) {
41-
Thread thread = (Thread) key;
4245
ThreadState threadState = new ThreadState(config, thread, liveThreads.get(thread));
4346
threads.add(threadState);
44-
45-
if (threadState.getId() == crashingThreadId) {
46-
threadState.setErrorReportingThread(true);
47-
}
4847
}
48+
4949
return threads;
5050
}
5151

@@ -63,14 +63,4 @@ public String getName() {
6363
public List<Stackframe> getStacktrace() {
6464
return Stackframe.getStacktrace(config, stackTraceElements);
6565
}
66-
67-
@JsonProperty("errorReportingThread")
68-
@JsonInclude(JsonInclude.Include.NON_NULL)
69-
public Boolean isErrorReportingThread() {
70-
return errorReportingThread;
71-
}
72-
73-
public void setErrorReportingThread(Boolean errorReportingThread) {
74-
this.errorReportingThread = errorReportingThread;
75-
}
7666
}
Lines changed: 5 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,12 @@
11
package com.bugsnag;
22

3-
import static org.junit.Assert.assertEquals;
4-
import static org.junit.Assert.assertFalse;
53
import static org.junit.Assert.assertNotNull;
64
import static org.junit.Assert.assertTrue;
75
import static org.junit.Assert.fail;
86

9-
import com.fasterxml.jackson.core.JsonProcessingException;
10-
import com.fasterxml.jackson.databind.JsonNode;
11-
import com.fasterxml.jackson.databind.ObjectMapper;
127
import org.junit.Before;
138
import org.junit.Test;
149

15-
import java.io.IOException;
1610
import java.lang.Exception;
1711
import java.util.List;
1812

@@ -31,15 +25,16 @@ public void setUp() throws Exception {
3125
}
3226

3327
@Test
34-
public void testThreadStateContainsCurrentThread() {
35-
int count = 0;
28+
public void testThreadStateDoesNotContainCurrentThread() {
3629

3730
for (ThreadState thread : threadStates) {
3831
if (thread.getId() == Thread.currentThread().getId()) {
39-
count++;
32+
fail();
4033
}
4134
}
42-
assertEquals(1, count);
35+
36+
// Just test that there is at least one thread
37+
assertTrue(threadStates.size() > 1);
4338
}
4439

4540
@Test
@@ -56,46 +51,4 @@ public void testThreadStacktrace() {
5651
assertNotNull(stacktrace);
5752
}
5853
}
59-
60-
/**
61-
* Verifies that the required values for 'thread' are serialised as an array
62-
*/
63-
@Test
64-
public void testSerialisation() throws Exception {
65-
JsonNode root = serialiseThreadStateToJson();
66-
67-
for (JsonNode jsonNode : root) {
68-
assertNotNull(jsonNode.get("id").asText());
69-
assertNotNull(jsonNode.get("name").asText());
70-
assertNotNull(jsonNode.get("stacktrace"));
71-
}
72-
}
73-
74-
/**
75-
* Verifies that the current thread is serialised as an object, and that only this value
76-
* contains the errorReportingThread boolean flag
77-
*/
78-
@Test
79-
public void testCurrentThread() throws Exception {
80-
JsonNode root = serialiseThreadStateToJson();
81-
long currentThreadId = Thread.currentThread().getId();
82-
int currentThreadCount = 0;
83-
84-
for (JsonNode jsonNode : root) {
85-
if (currentThreadId == jsonNode.get("id").asLong()) {
86-
assertTrue(jsonNode.get("errorReportingThread").asBoolean());
87-
currentThreadCount++;
88-
} else {
89-
assertFalse(jsonNode.has("errorReportingThread"));
90-
}
91-
}
92-
assertEquals(1, currentThreadCount);
93-
}
94-
95-
private JsonNode serialiseThreadStateToJson() throws IOException {
96-
ObjectMapper mapper = new ObjectMapper();
97-
String json = mapper.writeValueAsString(threadStates);
98-
return mapper.readTree(json);
99-
}
100-
10154
}

0 commit comments

Comments
 (0)