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:
parent
8df4d76aa2
commit
8f4adaedaf
1 changed files with 5 additions and 1 deletions
|
|
@ -128,9 +128,13 @@ public class MdnsSocket {
|
|||
* cannot be determined, returns -1.
|
||||
*/
|
||||
public int getInterfaceIndex() {
|
||||
if (multicastSocket.isClosed()) {
|
||||
sharedLog.e("Socket is closed");
|
||||
return -1;
|
||||
}
|
||||
try {
|
||||
return multicastSocket.getNetworkInterface().getIndex();
|
||||
} catch (SocketException e) {
|
||||
} catch (SocketException | NullPointerException e) {
|
||||
sharedLog.e("Failed to retrieve interface index for socket.", e);
|
||||
return -1;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue