Fix for NPE when getting network interface name (#14603)
Signed-off-by: Mark Hilbush <mark@hilbush.com>
This commit is contained in:
parent
596324635d
commit
d4b68b2df4
@ -12,9 +12,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.openhab.binding.benqprojector.internal.discovery;
|
package org.openhab.binding.benqprojector.internal.discovery;
|
||||||
|
|
||||||
import static org.openhab.binding.benqprojector.internal.BenqProjectorBindingConstants.DEFAULT_PORT;
|
import static org.openhab.binding.benqprojector.internal.BenqProjectorBindingConstants.*;
|
||||||
import static org.openhab.binding.benqprojector.internal.BenqProjectorBindingConstants.THING_PROPERTY_HOST;
|
|
||||||
import static org.openhab.binding.benqprojector.internal.BenqProjectorBindingConstants.THING_PROPERTY_PORT;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.DatagramPacket;
|
import java.net.DatagramPacket;
|
||||||
@ -59,8 +57,9 @@ public class MulticastListener {
|
|||||||
*/
|
*/
|
||||||
public MulticastListener(String ipv4Address) throws IOException, SocketException {
|
public MulticastListener(String ipv4Address) throws IOException, SocketException {
|
||||||
InetAddress ifAddress = InetAddress.getByName(ipv4Address);
|
InetAddress ifAddress = InetAddress.getByName(ipv4Address);
|
||||||
|
NetworkInterface netIF = NetworkInterface.getByInetAddress(ifAddress);
|
||||||
logger.debug("Discovery job using address {} on network interface {}", ifAddress.getHostAddress(),
|
logger.debug("Discovery job using address {} on network interface {}", ifAddress.getHostAddress(),
|
||||||
NetworkInterface.getByInetAddress(ifAddress).getName());
|
netIF != null ? netIF.getName() : "UNKNOWN");
|
||||||
socket = new MulticastSocket(AMX_MULTICAST_PORT);
|
socket = new MulticastSocket(AMX_MULTICAST_PORT);
|
||||||
socket.setInterface(ifAddress);
|
socket.setInterface(ifAddress);
|
||||||
socket.setSoTimeout(DEFAULT_SOCKET_TIMEOUT_SEC);
|
socket.setSoTimeout(DEFAULT_SOCKET_TIMEOUT_SEC);
|
||||||
|
|||||||
@ -1024,9 +1024,9 @@ public class BigAssFanHandler extends BaseThingHandler {
|
|||||||
deviceIsConnected = false;
|
deviceIsConnected = false;
|
||||||
try {
|
try {
|
||||||
ifAddress = InetAddress.getByName(ipv4Address);
|
ifAddress = InetAddress.getByName(ipv4Address);
|
||||||
|
NetworkInterface netIF = NetworkInterface.getByInetAddress(ifAddress);
|
||||||
logger.debug("Handler for {} using address {} on network interface {}", thing.getUID(), ipv4Address,
|
logger.debug("Handler for {} using address {} on network interface {}", thing.getUID(), ipv4Address,
|
||||||
NetworkInterface.getByInetAddress(ifAddress).getName());
|
netIF != null ? netIF.getName() : "UNKNOWN");
|
||||||
} catch (UnknownHostException e) {
|
} catch (UnknownHostException e) {
|
||||||
logger.warn("Handler for {} got UnknownHostException getting local IPv4 net interface: {}",
|
logger.warn("Handler for {} got UnknownHostException getting local IPv4 net interface: {}",
|
||||||
thing.getUID(), e.getMessage(), e);
|
thing.getUID(), e.getMessage(), e);
|
||||||
|
|||||||
@ -12,9 +12,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.openhab.binding.epsonprojector.internal.discovery;
|
package org.openhab.binding.epsonprojector.internal.discovery;
|
||||||
|
|
||||||
import static org.openhab.binding.epsonprojector.internal.EpsonProjectorBindingConstants.DEFAULT_PORT;
|
import static org.openhab.binding.epsonprojector.internal.EpsonProjectorBindingConstants.*;
|
||||||
import static org.openhab.binding.epsonprojector.internal.EpsonProjectorBindingConstants.THING_PROPERTY_HOST;
|
|
||||||
import static org.openhab.binding.epsonprojector.internal.EpsonProjectorBindingConstants.THING_PROPERTY_PORT;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.DatagramPacket;
|
import java.net.DatagramPacket;
|
||||||
@ -59,8 +57,9 @@ public class MulticastListener {
|
|||||||
*/
|
*/
|
||||||
public MulticastListener(String ipv4Address) throws IOException, SocketException {
|
public MulticastListener(String ipv4Address) throws IOException, SocketException {
|
||||||
InetAddress ifAddress = InetAddress.getByName(ipv4Address);
|
InetAddress ifAddress = InetAddress.getByName(ipv4Address);
|
||||||
|
NetworkInterface netIF = NetworkInterface.getByInetAddress(ifAddress);
|
||||||
logger.debug("Discovery job using address {} on network interface {}", ifAddress.getHostAddress(),
|
logger.debug("Discovery job using address {} on network interface {}", ifAddress.getHostAddress(),
|
||||||
NetworkInterface.getByInetAddress(ifAddress).getName());
|
netIF != null ? netIF.getName() : "UNKNOWN");
|
||||||
socket = new MulticastSocket(AMX_MULTICAST_PORT);
|
socket = new MulticastSocket(AMX_MULTICAST_PORT);
|
||||||
socket.setInterface(ifAddress);
|
socket.setInterface(ifAddress);
|
||||||
socket.setSoTimeout(DEFAULT_SOCKET_TIMEOUT_SEC);
|
socket.setSoTimeout(DEFAULT_SOCKET_TIMEOUT_SEC);
|
||||||
|
|||||||
@ -63,8 +63,9 @@ public class MulticastListener {
|
|||||||
*/
|
*/
|
||||||
public MulticastListener(String ipv4Address) throws IOException, SocketException {
|
public MulticastListener(String ipv4Address) throws IOException, SocketException {
|
||||||
InetAddress ifAddress = InetAddress.getByName(ipv4Address);
|
InetAddress ifAddress = InetAddress.getByName(ipv4Address);
|
||||||
|
NetworkInterface netIF = NetworkInterface.getByInetAddress(ifAddress);
|
||||||
logger.debug("Discovery job using address {} on network interface {}", ifAddress.getHostAddress(),
|
logger.debug("Discovery job using address {} on network interface {}", ifAddress.getHostAddress(),
|
||||||
NetworkInterface.getByInetAddress(ifAddress).getName());
|
netIF != null ? netIF.getName() : "UNKNOWN");
|
||||||
socket = new MulticastSocket(GC_MULTICAST_PORT);
|
socket = new MulticastSocket(GC_MULTICAST_PORT);
|
||||||
socket.setInterface(ifAddress);
|
socket.setInterface(ifAddress);
|
||||||
socket.setSoTimeout(DEFAULT_SOCKET_TIMEOUT);
|
socket.setSoTimeout(DEFAULT_SOCKET_TIMEOUT);
|
||||||
|
|||||||
@ -105,8 +105,9 @@ public class GlobalCacheHandler extends BaseThingHandler {
|
|||||||
logger.debug("Initializing thing {}", thingID());
|
logger.debug("Initializing thing {}", thingID());
|
||||||
try {
|
try {
|
||||||
ifAddress = InetAddress.getByName(ipv4Address);
|
ifAddress = InetAddress.getByName(ipv4Address);
|
||||||
|
NetworkInterface netIF = NetworkInterface.getByInetAddress(ifAddress);
|
||||||
logger.debug("Handler using address {} on network interface {}", ifAddress.getHostAddress(),
|
logger.debug("Handler using address {} on network interface {}", ifAddress.getHostAddress(),
|
||||||
NetworkInterface.getByInetAddress(ifAddress).getName());
|
netIF != null ? netIF.getName() : "UNKNOWN");
|
||||||
} catch (SocketException e) {
|
} catch (SocketException e) {
|
||||||
logger.error("Handler got Socket exception creating multicast socket: {}", e.getMessage());
|
logger.error("Handler got Socket exception creating multicast socket: {}", e.getMessage());
|
||||||
markThingOfflineWithError(ThingStatusDetail.OFFLINE.CONFIGURATION_ERROR, "No suitable network interface");
|
markThingOfflineWithError(ThingStatusDetail.OFFLINE.CONFIGURATION_ERROR, "No suitable network interface");
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user