Handle closed socket and NPE properly
Don't get interfaceIndex if the socket is closed. Properly catch NPE instead of letting is propagating. Test: TH Change-Id: If962541e67dd6323426e46bc7a1f118786f83b9b
This commit is contained in:
@@ -128,9 +128,13 @@ public class MdnsSocket {
|
|||||||
* cannot be determined, returns -1.
|
* cannot be determined, returns -1.
|
||||||
*/
|
*/
|
||||||
public int getInterfaceIndex() {
|
public int getInterfaceIndex() {
|
||||||
|
if (multicastSocket.isClosed()) {
|
||||||
|
sharedLog.e("Socket is closed");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
return multicastSocket.getNetworkInterface().getIndex();
|
return multicastSocket.getNetworkInterface().getIndex();
|
||||||
} catch (SocketException e) {
|
} catch (SocketException | NullPointerException e) {
|
||||||
sharedLog.e("Failed to retrieve interface index for socket.", e);
|
sharedLog.e("Failed to retrieve interface index for socket.", e);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user