Check null NetworkSpecifier before redacting

Do null check before redacting, since NetworkSpecifier will not
always be attached. For example, NetworkSpecifier of wifi
network is only attached when a wifi network is created
in response to a network request with specifier attached.

Test: atest CtsNetTestCases:android.net.cts.ConnectivityManagerTest#testGetAllNetworkStateSnapshots \
      --rerun-until-failure 100
      (tested on cuttlefish mobile and wifi)
Bug: 191944987
Original-Change: https://android-review.googlesource.com/1747893
Merged-In: I5df3547995111fe6340facb94a577296d2228694
Change-Id: I5df3547995111fe6340facb94a577296d2228694
diff --git a/tests/cts/net/src/android/net/cts/ConnectivityManagerTest.java b/tests/cts/net/src/android/net/cts/ConnectivityManagerTest.java
index 4c967b8..ed477a2 100644
--- a/tests/cts/net/src/android/net/cts/ConnectivityManagerTest.java
+++ b/tests/cts/net/src/android/net/cts/ConnectivityManagerTest.java
@@ -537,8 +537,10 @@
                     Objects.requireNonNull(mCm.getNetworkCapabilities(network));
             // Redact specifier of the capabilities of the snapshot before comparing since
             // the result returned from getNetworkCapabilities always get redacted.
+            final NetworkSpecifier snapshotCapSpecifier =
+                    snapshot.getNetworkCapabilities().getNetworkSpecifier();
             final NetworkSpecifier redactedSnapshotCapSpecifier =
-                    snapshot.getNetworkCapabilities().getNetworkSpecifier().redact();
+                    snapshotCapSpecifier == null ? null : snapshotCapSpecifier.redact();
             assertEquals("", caps.describeImmutableDifferences(
                     snapshot.getNetworkCapabilities()
                             .setNetworkSpecifier(redactedSnapshotCapSpecifier)));