@@ -359,7 +359,9 @@ void enableExceptionHandling(
359359 new CrashlyticsUncaughtExceptionHandler .CrashListener () {
360360 @ Override
361361 public void onUncaughtException (
362- SettingsDataProvider settingsDataProvider , Thread thread , Throwable ex ) {
362+ @ NonNull SettingsDataProvider settingsDataProvider ,
363+ @ NonNull Thread thread ,
364+ @ NonNull Throwable ex ) {
363365 handleUncaughtException (settingsDataProvider , thread , ex );
364366 }
365367 };
@@ -369,7 +371,9 @@ public void onUncaughtException(
369371 }
370372
371373 synchronized void handleUncaughtException (
372- SettingsDataProvider settingsDataProvider , final Thread thread , final Throwable ex ) {
374+ @ NonNull SettingsDataProvider settingsDataProvider ,
375+ @ NonNull final Thread thread ,
376+ @ NonNull final Throwable ex ) {
373377
374378 Logger .getLogger ()
375379 .d (
@@ -422,6 +426,12 @@ public Task<Void> call() throws Exception {
422426 @ Override
423427 public Task <Void > then (@ Nullable AppSettingsData appSettingsData )
424428 throws Exception {
429+ if (appSettingsData == null ) {
430+ Logger .getLogger ()
431+ .w (
432+ "Received null app settings, cannot send reports at crash time." );
433+ return Tasks .forResult (null );
434+ }
425435 // Data collection is enabled, so it's safe to send the report.
426436 boolean dataCollectionToken = true ;
427437 sendSessionReports (appSettingsData , dataCollectionToken );
@@ -567,6 +577,12 @@ public Task<Void> call() throws Exception {
567577 @ Override
568578 public Task <Void > then (@ Nullable AppSettingsData appSettingsData )
569579 throws Exception {
580+ if (appSettingsData == null ) {
581+ Logger .getLogger ()
582+ .w (
583+ "Received null app settings, cannot send reports during app startup." );
584+ return Tasks .forResult (null );
585+ }
570586 // Append the most recent org ID to each report file, even if it
571587 // was already appended during the crash time upload. This way
572588 // we'll always have the most recent value available attached.
@@ -597,7 +613,7 @@ public Task<Void> then(@Nullable AppSettingsData appSettingsData)
597613 private ReportUploader .Provider defaultReportUploader () {
598614 return new ReportUploader .Provider () {
599615 @ Override
600- public ReportUploader createReportUploader (AppSettingsData appSettingsData ) {
616+ public ReportUploader createReportUploader (@ NonNull AppSettingsData appSettingsData ) {
601617 final String reportsUrl = appSettingsData .reportsUrl ;
602618 final String ndkReportsUrl = appSettingsData .ndkReportsUrl ;
603619 final String organizationId = appSettingsData .organizationId ;
@@ -630,7 +646,7 @@ public Void call() throws Exception {
630646 }
631647
632648 /** Log a caught exception - write out Throwable as event section of protobuf */
633- void writeNonFatalException (final Thread thread , final Throwable ex ) {
649+ void writeNonFatalException (@ NonNull final Thread thread , @ NonNull final Throwable ex ) {
634650 // Capture and close over the current time, so that we get the exact call time,
635651 // rather than the time at which the task executes.
636652 final Date time = new Date ();
@@ -660,7 +676,7 @@ void setCustomKey(String key, String value) {
660676 if (context != null && CommonUtils .isAppDebuggable (context )) {
661677 throw ex ;
662678 } else {
663- Logger .getLogger ().e ("Attempting to set custom attribute with null key, ignoring." , null );
679+ Logger .getLogger ().e ("Attempting to set custom attribute with null key, ignoring." );
664680 return ;
665681 }
666682 }
@@ -1135,7 +1151,8 @@ private static long getTimestampSeconds(Date date) {
11351151 }
11361152
11371153 /** Removes dashes in the Crashlytics session identifier to conform to Firebase constraints. */
1138- private static String makeFirebaseSessionIdentifier (String sessionIdentifier ) {
1154+ @ NonNull
1155+ private static String makeFirebaseSessionIdentifier (@ NonNull String sessionIdentifier ) {
11391156 return sessionIdentifier .replaceAll ("-" , "" );
11401157 }
11411158
@@ -1152,7 +1169,7 @@ private void writeFatal(Thread thread, Throwable ex, long eventTime) {
11521169 final String currentSessionId = getCurrentSessionId ();
11531170
11541171 if (currentSessionId == null ) {
1155- Logger .getLogger ().e ("Tried to write a fatal exception while no session was open." , null );
1172+ Logger .getLogger ().e ("Tried to write a fatal exception while no session was open." );
11561173 return ;
11571174 }
11581175
@@ -1171,11 +1188,11 @@ private void writeFatal(Thread thread, Throwable ex, long eventTime) {
11711188 * Not synchronized/locked. Must be executed from the single thread executor service used by this
11721189 * class.
11731190 */
1174- private void doWriteNonFatal (Thread thread , Throwable ex , long eventTime ) {
1191+ private void doWriteNonFatal (@ NonNull Thread thread , @ NonNull Throwable ex , long eventTime ) {
11751192 final String currentSessionId = getCurrentSessionId ();
11761193
11771194 if (currentSessionId == null ) {
1178- Logger .getLogger ().e ("Tried to write a non-fatal exception while no session was open." , null );
1195+ Logger .getLogger ().d ("Tried to write a non-fatal exception while no session was open." );
11791196 return ;
11801197 }
11811198
@@ -1230,8 +1247,8 @@ private void writeSessionPartFile(
12301247 }
12311248 }
12321249
1233- private static void appendToProtoFile (File file , CodedOutputStreamWriteAction writeAction )
1234- throws Exception {
1250+ private static void appendToProtoFile (
1251+ @ NonNull File file , @ NonNull CodedOutputStreamWriteAction writeAction ) throws Exception {
12351252 FileOutputStream fos = null ;
12361253 CodedOutputStream cos = null ;
12371254 try {
@@ -1584,16 +1601,19 @@ private void writeInitialPartsTo(CodedOutputStream cos, String sessionId) throws
15841601 listFilesMatching (new FileNameContainsFilter (sessionId + tag + SESSION_FILE_EXTENSION ));
15851602
15861603 if (sessionPartFiles .length == 0 ) {
1587- Logger .getLogger ().e ("Can't find " + tag + " data for session ID " + sessionId , null );
1604+ Logger .getLogger ().d ("Can't find " + tag + " data for session ID " + sessionId );
15881605 } else {
15891606 Logger .getLogger ().d ("Collecting " + tag + " data for session ID " + sessionId );
15901607 writeToCosFromFile (cos , sessionPartFiles [0 ]);
15911608 }
15921609 }
15931610 }
15941611
1595- private static void appendOrganizationIdToSessionFile (String organizationId , File file )
1596- throws Exception {
1612+ private static void appendOrganizationIdToSessionFile (
1613+ @ Nullable String organizationId , @ NonNull File file ) throws Exception {
1614+ if (organizationId == null ) {
1615+ return ;
1616+ }
15971617 appendToProtoFile (
15981618 file ,
15991619 new CodedOutputStreamWriteAction () {
@@ -1610,7 +1630,7 @@ public void writeTo(CodedOutputStream cos) throws Exception {
16101630 */
16111631 private static void writeToCosFromFile (CodedOutputStream cos , File file ) throws IOException {
16121632 if (!file .exists ()) {
1613- Logger .getLogger ().e ("Tried to include a file that doesn't exist: " + file .getName (), null );
1633+ Logger .getLogger ().e ("Tried to include a file that doesn't exist: " + file .getName ());
16141634 return ;
16151635 }
16161636
@@ -1698,7 +1718,7 @@ private CreateReportSpiCall getCreateReportSpiCall(String reportsUrl, String ndk
16981718 return new CompositeCreateReportSpiCall (defaultCreateReportSpiCall , nativeCreateReportSpiCall );
16991719 }
17001720
1701- private void sendSessionReports (AppSettingsData appSettings , boolean dataCollectionToken )
1721+ private void sendSessionReports (@ NonNull AppSettingsData appSettings , boolean dataCollectionToken )
17021722 throws Exception {
17031723 final Context context = getContext ();
17041724 final ReportUploader reportUploader = reportUploaderProvider .createReportUploader (appSettings );
@@ -1842,6 +1862,7 @@ public void run() {
18421862 }
18431863 }
18441864
1865+ @ NonNull
18451866 static List <NativeSessionFile > getNativeSessionFiles (
18461867 NativeSessionFileProvider fileProvider ,
18471868 String previousSessionId ,
@@ -1857,7 +1878,7 @@ static List<NativeSessionFile> getNativeSessionFiles(
18571878 try {
18581879 binaryImageBytes =
18591880 NativeFileUtils .binaryImagesJsonFromMapsFile (fileProvider .getBinaryImagesFile (), context );
1860- } catch (IOException e ) {
1881+ } catch (Exception e ) {
18611882 // Keep processing, we'll add an empty binaryImages object.
18621883 }
18631884
0 commit comments