Fix the potential NullPointerException.

The networkAttributesParcelable retrieved from IpMemoryStore might be
null, it might cause crash with NullPointerException when attepmting
to read from the field on a null object reference.

Bug: 135174345
Test: atest FrameworksNetTests NetworkStackTests
Merged-In: I658fbba3e18c5c640ed7d445d2cd59c4221e055f
Merged-In: Ie6b5c293b4ca17622674d5f735a9d62e04410088

(cherry picked from commit 4769936f59)

Change-Id: I3be6e57f6f8c56f828b025828aae0640248d23a9
This commit is contained in:
Xiao Ma
2019-06-08 04:52:31 -07:00
parent 6d371e092e
commit 782393ffcb
2 changed files with 6 additions and 3 deletions

View File

@@ -127,6 +127,7 @@ public class NetworkAttributes {
@Nullable
private static InetAddress getByAddressOrNull(@Nullable final byte[] address) {
if (null == address) return null;
try {
return InetAddress.getByAddress(address);
} catch (UnknownHostException e) {
@@ -227,7 +228,9 @@ public class NetworkAttributes {
}
/**
* Set the lease expiry timestamp of assigned v4 address.
* Set the lease expiry timestamp of assigned v4 address. Long.MAX_VALUE is used
* to represent "infinite lease".
*
* @param assignedV4AddressExpiry The lease expiry timestamp of assigned v4 address.
* @return This builder.
*/

View File

@@ -40,8 +40,8 @@ public interface OnNetworkAttributesRetrievedListener {
// NonNull, but still don't crash the system server if null
if (null != listener) {
listener.onNetworkAttributesRetrieved(
new Status(statusParcelable), l2Key,
new NetworkAttributes(networkAttributesParcelable));
new Status(statusParcelable), l2Key, null == networkAttributesParcelable
? null : new NetworkAttributes(networkAttributesParcelable));
}
}