From 8869a14aeddfa2da17855938039cac4255fe4d8a Mon Sep 17 00:00:00 2001 From: Matthew Robertson Date: Fri, 11 Oct 2024 15:01:01 -0400 Subject: [PATCH] Fix IllegalStateException when starting a trace before Firebase init (#6371) Fix IllegalStateException when starting a trace before Firebase initializes. This can happen if you manually initialize Firebase. See #4693 --- firebase-perf/CHANGELOG.md | 1 + .../google/firebase/perf/config/RemoteConfigManager.java | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/firebase-perf/CHANGELOG.md b/firebase-perf/CHANGELOG.md index 2f370bab159..8f376deff25 100644 --- a/firebase-perf/CHANGELOG.md +++ b/firebase-perf/CHANGELOG.md @@ -1,4 +1,5 @@ # Unreleased +* [fixed] Fix IllegalStateException when starting a trace before Firebase initializes. * [changed] Updated protobuf dependency to `3.25.5` to fix [CVE-2024-7254](https://github.com/advisories/GHSA-735f-pc8j-v9w8). diff --git a/firebase-perf/src/main/java/com/google/firebase/perf/config/RemoteConfigManager.java b/firebase-perf/src/main/java/com/google/firebase/perf/config/RemoteConfigManager.java index 88351ae6166..36d8c272aef 100644 --- a/firebase-perf/src/main/java/com/google/firebase/perf/config/RemoteConfigManager.java +++ b/firebase-perf/src/main/java/com/google/firebase/perf/config/RemoteConfigManager.java @@ -88,7 +88,13 @@ private RemoteConfigManager() { @VisibleForTesting @SuppressWarnings("FirebaseUseExplicitDependencies") static long getInitialStartupMillis() { - StartupTime startupTime = FirebaseApp.getInstance().get(StartupTime.class); + StartupTime startupTime = null; + try { + startupTime = FirebaseApp.getInstance().get(StartupTime.class); + } catch (IllegalStateException ex) { + // This can happen if you start a trace before Firebase is init + logger.debug("Unable to get StartupTime instance."); + } if (startupTime != null) { return startupTime.getEpochMillis(); } else {