[go: nahoru, domu]

Crash loudly if passed a null/destroyed profile to SyncServiceFactory.getForProfile.

(cherry picked from commit 9aa74a6030414f43982b6e45c8f100ad301fe811)

Bug: 327687076
Change-Id: Id750b58d42b3a1a81620eda0b5d400356ce0f009
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5341935
Commit-Queue: Ted Choc <tedchoc@chromium.org>
Reviewed-by: Theresa Sullivan <twellington@chromium.org>
Cr-Original-Commit-Position: refs/heads/main@{#1268210}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5356561
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Cr-Commit-Position: refs/branch-heads/6312@{#479}
Cr-Branched-From: 6711dcdae48edaf98cbc6964f90fac85b7d9986e-refs/heads/main@{#1262506}
diff --git a/chrome/browser/sync/android/java/src/org/chromium/chrome/browser/sync/SyncServiceFactory.java b/chrome/browser/sync/android/java/src/org/chromium/chrome/browser/sync/SyncServiceFactory.java
index 6442eae..0bd68cf 100644
--- a/chrome/browser/sync/android/java/src/org/chromium/chrome/browser/sync/SyncServiceFactory.java
+++ b/chrome/browser/sync/android/java/src/org/chromium/chrome/browser/sync/SyncServiceFactory.java
@@ -31,6 +31,11 @@
     public static @Nullable SyncService getForProfile(Profile profile) {
         ThreadUtils.assertOnUiThread();
         if (sSyncServiceForTest != null) return sSyncServiceForTest;
+        if (profile == null) {
+            throw new IllegalArgumentException(
+                    "Attempting to access the SyncService with a null profile");
+        }
+        profile.ensureNativeInitialized();
         return SyncServiceFactoryJni.get().getForProfile(profile);
     }