Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[benqprojector] Fix NullPointerException when getting network interface name #14603

Merged
merged 1 commit into from
Mar 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
*/
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.THING_PROPERTY_HOST;
import static org.openhab.binding.benqprojector.internal.BenqProjectorBindingConstants.THING_PROPERTY_PORT;
import static org.openhab.binding.benqprojector.internal.BenqProjectorBindingConstants.*;

import java.io.IOException;
import java.net.DatagramPacket;
Expand Down Expand Up @@ -59,8 +57,9 @@ public class MulticastListener {
*/
public MulticastListener(String ipv4Address) throws IOException, SocketException {
InetAddress ifAddress = InetAddress.getByName(ipv4Address);
NetworkInterface netIF = NetworkInterface.getByInetAddress(ifAddress);
logger.debug("Discovery job using address {} on network interface {}", ifAddress.getHostAddress(),
NetworkInterface.getByInetAddress(ifAddress).getName());
netIF != null ? netIF.getName() : "UNKNOWN");
jlaur marked this conversation as resolved.
Show resolved Hide resolved
socket = new MulticastSocket(AMX_MULTICAST_PORT);
socket.setInterface(ifAddress);
socket.setSoTimeout(DEFAULT_SOCKET_TIMEOUT_SEC);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1024,9 +1024,9 @@ public ConnectionManager(@Nullable String ipv4Address) {
deviceIsConnected = false;
try {
ifAddress = InetAddress.getByName(ipv4Address);

NetworkInterface netIF = NetworkInterface.getByInetAddress(ifAddress);
logger.debug("Handler for {} using address {} on network interface {}", thing.getUID(), ipv4Address,
NetworkInterface.getByInetAddress(ifAddress).getName());
netIF != null ? netIF.getName() : "UNKNOWN");
} catch (UnknownHostException e) {
logger.warn("Handler for {} got UnknownHostException getting local IPv4 net interface: {}",
thing.getUID(), e.getMessage(), e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
*/
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.THING_PROPERTY_HOST;
import static org.openhab.binding.epsonprojector.internal.EpsonProjectorBindingConstants.THING_PROPERTY_PORT;
import static org.openhab.binding.epsonprojector.internal.EpsonProjectorBindingConstants.*;

import java.io.IOException;
import java.net.DatagramPacket;
Expand Down Expand Up @@ -59,8 +57,9 @@ public class MulticastListener {
*/
public MulticastListener(String ipv4Address) throws IOException, SocketException {
InetAddress ifAddress = InetAddress.getByName(ipv4Address);
NetworkInterface netIF = NetworkInterface.getByInetAddress(ifAddress);
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.setInterface(ifAddress);
socket.setSoTimeout(DEFAULT_SOCKET_TIMEOUT_SEC);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@ public class MulticastListener {
*/
public MulticastListener(String ipv4Address) throws IOException, SocketException {
InetAddress ifAddress = InetAddress.getByName(ipv4Address);
NetworkInterface netIF = NetworkInterface.getByInetAddress(ifAddress);
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.setInterface(ifAddress);
socket.setSoTimeout(DEFAULT_SOCKET_TIMEOUT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,9 @@ public void initialize() {
logger.debug("Initializing thing {}", thingID());
try {
ifAddress = InetAddress.getByName(ipv4Address);
NetworkInterface netIF = NetworkInterface.getByInetAddress(ifAddress);
logger.debug("Handler using address {} on network interface {}", ifAddress.getHostAddress(),
NetworkInterface.getByInetAddress(ifAddress).getName());
netIF != null ? netIF.getName() : "UNKNOWN");
} catch (SocketException e) {
logger.error("Handler got Socket exception creating multicast socket: {}", e.getMessage());
markThingOfflineWithError(ThingStatusDetail.OFFLINE.CONFIGURATION_ERROR, "No suitable network interface");
Expand Down