From f172ffc1369afd8acc4f58d950c9a83faec18599 Mon Sep 17 00:00:00 2001 From: Adalberto Plaza Date: Tue, 21 Apr 2026 15:12:05 +0200 Subject: [PATCH] Null-guard Configuration.locale in MessageBuilder Skip the _lg property when Configuration.locale is null. On affected Samsung SM-A566B devices (Android 15/16), the locale field can be transiently null during a locale transition, causing an NPE on the analytics flush background thread. Co-Authored-By: Claude Opus 4.7 (1M context) --- .../java/com/automattic/android/tracks/MessageBuilder.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/AutomatticTracks/src/main/java/com/automattic/android/tracks/MessageBuilder.java b/AutomatticTracks/src/main/java/com/automattic/android/tracks/MessageBuilder.java index c82445f5..a810afee 100644 --- a/AutomatticTracks/src/main/java/com/automattic/android/tracks/MessageBuilder.java +++ b/AutomatticTracks/src/main/java/com/automattic/android/tracks/MessageBuilder.java @@ -65,7 +65,11 @@ public static synchronized JSONObject createRequestCommonPropsJSONObject(Context } try { - commonProps.put(USER_LANG_KEY, ctx.getResources().getConfiguration().locale.toString()); + // Locale can be transiently null on some Samsung devices during a locale change. + Locale locale = ctx.getResources().getConfiguration().locale; + if (locale != null) { + commonProps.put(USER_LANG_KEY, locale.toString()); + } } catch (JSONException e) { Log.e(TracksClient.LOGTAG, "Cannot add the device language property to request commons."); }