From 50756739b5492d985027ffb5cbff7f5612b41ff9 Mon Sep 17 00:00:00 2001 From: Treehugger Robot Date: Tue, 7 Apr 2020 06:59:06 +0000 Subject: [PATCH] Fix a stupid NPE Okay so this is really not a behavior change as it converts an NPE into an illegal argument exception, but still, that's what should happen (and that's what the upcoming test actually tests for). Test: upcoming NetworkAgentTest Bug: 139268426 Change-Id: I0d9b8cb8f8dcb587b9430b486b863efb9e9e77ef Merged-In: I3e17211c03bc74426bf5e2e414ec322d73b0060b (cherry picked from commit 827d7ceea1e83cca9ba3f6189e20b6780c0194ed, aosp/1277595) --- core/java/android/net/NetworkAgent.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/java/android/net/NetworkAgent.java b/core/java/android/net/NetworkAgent.java index c42dacc187..e9bcefef50 100644 --- a/core/java/android/net/NetworkAgent.java +++ b/core/java/android/net/NetworkAgent.java @@ -556,12 +556,12 @@ public abstract class NetworkAgent { @NonNull public Network register() { if (VDBG) log("Registering NetworkAgent"); - final ConnectivityManager cm = (ConnectivityManager) mInitialConfiguration.context - .getSystemService(Context.CONNECTIVITY_SERVICE); synchronized (mRegisterLock) { if (mNetwork != null) { throw new IllegalStateException("Agent already registered"); } + final ConnectivityManager cm = (ConnectivityManager) mInitialConfiguration.context + .getSystemService(Context.CONNECTIVITY_SERVICE); mNetwork = cm.registerNetworkAgent(new Messenger(mHandler), new NetworkInfo(mInitialConfiguration.info), mInitialConfiguration.properties, mInitialConfiguration.capabilities,