Skip to content

Commit caf07e0

Browse files
committed
Speculative fix for issue #3084. NullPointerException is encountered specifically on Android version 8.1.0, this is due to String.format inserted with Double values.
The proposed fix is to use DecimalFormat to format the values before being inserted in String.format
1 parent e2f4a3e commit caf07e0

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

firebase-perf/src/main/java/com/google/firebase/perf/transport/TransportManager.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
import com.google.firebase.perf.v1.TraceMetric;
5353
import java.lang.ref.WeakReference;
5454
import java.util.Collections;
55+
import java.text.DecimalFormat;
5556
import java.util.Locale;
5657
import java.util.Map;
5758
import java.util.concurrent.ConcurrentHashMap;
@@ -617,9 +618,9 @@ private static String getLogcatMsg(TraceMetric traceMetric) {
617618
long durationInUs = traceMetric.getDurationUs();
618619
return String.format(
619620
Locale.ENGLISH,
620-
"trace metric: %s (duration: %.4fms)",
621+
"trace metric: %s (duration: %sms)",
621622
traceMetric.getName(),
622-
durationInUs / 1000.0);
623+
new DecimalFormat("#.####").format(durationInUs / 1000.0));
623624
}
624625

625626
private static String getLogcatMsg(NetworkRequestMetric networkRequestMetric) {
@@ -635,10 +636,10 @@ private static String getLogcatMsg(NetworkRequestMetric networkRequestMetric) {
635636

636637
return String.format(
637638
Locale.ENGLISH,
638-
"network request trace: %s (responseCode: %s, responseTime: %.4fms)",
639+
"network request trace: %s (responseCode: %s, responseTime: %sms)",
639640
networkRequestMetric.getUrl(),
640641
responseCode,
641-
durationInUs / 1000.0);
642+
new DecimalFormat("#.####").format(durationInUs / 1000.0));
642643
}
643644

644645
private static String getLogcatMsg(GaugeMetric gaugeMetric) {

0 commit comments

Comments
 (0)