File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11# Changelog
22
3+ ## 3.4.2 (2018-11-28)
4+
5+ * Ensure session counts are thread safe
6+ [ #122 ] ( https://github.com/bugsnag/bugsnag-java/pull/122 )
7+
38## 3.4.1
49
510(Skipped, duplicate of 3.4.0)
Original file line number Diff line number Diff line change @@ -137,16 +137,16 @@ Map<String, Object> getSession() {
137137 void setSession (Session session ) {
138138 if (session == null ) {
139139 sessionMap = null ;
140+ } else {
141+ sessionMap = new HashMap <String , Object >();
142+ sessionMap .put ("id" , session .getId ());
143+ sessionMap .put ("startedAt" , session .getStartedAt ());
144+
145+ Map <String , Object > handledCounts = new HashMap <String , Object >();
146+ handledCounts .put ("handled" , session .getHandledCount ());
147+ handledCounts .put ("unhandled" , session .getUnhandledCount ());
148+ sessionMap .put ("events" , handledCounts );
140149 }
141-
142- sessionMap = new HashMap <String , Object >();
143- sessionMap .put ("id" , session .getId ());
144- sessionMap .put ("startedAt" , session .getStartedAt ());
145-
146- Map <String , Object > handledCounts = new HashMap <String , Object >();
147- handledCounts .put ("handled" , session .getHandledCount ());
148- handledCounts .put ("unhandled" , session .getUnhandledCount ());
149- sessionMap .put ("events" , handledCounts );
150150 }
151151
152152 /**
Original file line number Diff line number Diff line change 55import static org .junit .Assert .assertNotNull ;
66import static org .junit .Assert .assertNull ;
77
8+ import com .fasterxml .jackson .annotation .JsonInclude ;
89import com .fasterxml .jackson .databind .JsonNode ;
910import com .fasterxml .jackson .databind .ObjectMapper ;
1011import org .junit .Before ;
@@ -31,6 +32,9 @@ public void setUp() {
3132 config .appVersion = "1.2.3" ;
3233 config .releaseStage = "dev" ;
3334 report = new Report (config , new RuntimeException ());
35+
36+ // Only include properties with non-null values
37+ mapper .setSerializationInclusion (JsonInclude .Include .NON_NULL );
3438 }
3539
3640 private JsonNode generateJson (ObjectMapper mapper ,
@@ -67,6 +71,17 @@ public void testWithoutSessionSerialisation() throws Throwable {
6771 assertNull (rootNode .get ("events" ).get ("session" ));
6872 }
6973
74+ @ Test
75+ public void testNullSession () throws Throwable {
76+ report .setSession (null );
77+
78+ JsonNode rootNode = generateJson (mapper , config , report );
79+ validateErrorReport (rootNode );
80+
81+ JsonNode session = rootNode .get ("events" ).get (0 ).get ("session" );
82+ assertNull (session );
83+ }
84+
7085 private void validateErrorReport (JsonNode rootNode ) {
7186 assertNotNull (rootNode );
7287 assertNotNull (rootNode .get ("apiKey" ).asText ());
You can’t perform that action at this time.
0 commit comments