Skip to content

Commit 052fc33

Browse files
committed
Fix nullability for nonfatals & clean up logging calls
1 parent 8f6eaaf commit 052fc33

File tree

3 files changed

+12
-13
lines changed

3 files changed

+12
-13
lines changed

firebase-crashlytics/src/main/java/com/google/firebase/crashlytics/FirebaseCrashlytics.java

+4
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,10 @@ public static FirebaseCrashlytics getInstance() {
123123
* @param throwable a {@link Throwable} to be recorded as a non-fatal event.
124124
*/
125125
public void recordException(@NonNull Throwable throwable) {
126+
if (throwable == null) { // Users could call this with null despite the annotation.
127+
Logger.getLogger().w("Crashlytics is ignoring a request to log a null exception.");
128+
return;
129+
}
126130
core.logException(throwable);
127131
}
128132

firebase-crashlytics/src/main/java/com/google/firebase/crashlytics/internal/common/CrashlyticsController.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,7 @@ public Void call() throws Exception {
646646
}
647647

648648
/** Log a caught exception - write out Throwable as event section of protobuf */
649-
void writeNonFatalException(final Thread thread, final Throwable ex) {
649+
void writeNonFatalException(@NonNull final Thread thread, @NonNull final Throwable ex) {
650650
// Capture and close over the current time, so that we get the exact call time,
651651
// rather than the time at which the task executes.
652652
final Date time = new Date();
@@ -676,7 +676,7 @@ void setCustomKey(String key, String value) {
676676
if (context != null && CommonUtils.isAppDebuggable(context)) {
677677
throw ex;
678678
} else {
679-
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.");
680680
return;
681681
}
682682
}
@@ -1169,7 +1169,7 @@ private void writeFatal(Thread thread, Throwable ex, long eventTime) {
11691169
final String currentSessionId = getCurrentSessionId();
11701170

11711171
if (currentSessionId == null) {
1172-
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.");
11731173
return;
11741174
}
11751175

@@ -1188,11 +1188,11 @@ private void writeFatal(Thread thread, Throwable ex, long eventTime) {
11881188
* Not synchronized/locked. Must be executed from the single thread executor service used by this
11891189
* class.
11901190
*/
1191-
private void doWriteNonFatal(Thread thread, Throwable ex, long eventTime) {
1191+
private void doWriteNonFatal(@NonNull Thread thread, @NonNull Throwable ex, long eventTime) {
11921192
final String currentSessionId = getCurrentSessionId();
11931193

11941194
if (currentSessionId == null) {
1195-
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.");
11961196
return;
11971197
}
11981198

@@ -1601,7 +1601,7 @@ private void writeInitialPartsTo(CodedOutputStream cos, String sessionId) throws
16011601
listFilesMatching(new FileNameContainsFilter(sessionId + tag + SESSION_FILE_EXTENSION));
16021602

16031603
if (sessionPartFiles.length == 0) {
1604-
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);
16051605
} else {
16061606
Logger.getLogger().d("Collecting " + tag + " data for session ID " + sessionId);
16071607
writeToCosFromFile(cos, sessionPartFiles[0]);
@@ -1630,7 +1630,7 @@ public void writeTo(CodedOutputStream cos) throws Exception {
16301630
*/
16311631
private static void writeToCosFromFile(CodedOutputStream cos, File file) throws IOException {
16321632
if (!file.exists()) {
1633-
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());
16341634
return;
16351635
}
16361636

firebase-crashlytics/src/main/java/com/google/firebase/crashlytics/internal/common/CrashlyticsCore.java

+1-6
Original file line numberDiff line numberDiff line change
@@ -311,12 +311,7 @@ public static String getVersion() {
311311
* Throwable was thrown. The Throwable will always be processed on a background thread, so it is
312312
* safe to invoke this method from the main thread.
313313
*/
314-
public void logException(final Throwable throwable) {
315-
if (throwable == null) {
316-
Logger.getLogger().w("Crashlytics is ignoring a request to log a null exception.");
317-
return;
318-
}
319-
314+
public void logException(@NonNull Throwable throwable) {
320315
controller.writeNonFatalException(Thread.currentThread(), throwable);
321316
}
322317

0 commit comments

Comments
 (0)