On my machine InetAddress.getByName(hostname()) (in NetworkUtil::nic) returns ipv4 loopback address (127.0.0.1).
(this happens only with virtual interfaces from openconnect up)
It result in NPE in all mac addr using functionality - e.g. see stack.txt
This seem like regression, in 4.1.3 this functionality works fine.
My ugly workaround
Index: src/main/java/com/github/f4b6a3/uuid/util/internal/NetworkUtil.java
===================================================================
diff --git a/src/main/java/com/github/f4b6a3/uuid/util/internal/NetworkUtil.java b/src/main/java/com/github/f4b6a3/uuid/util/internal/NetworkUtil.java
--- a/src/main/java/com/github/f4b6a3/uuid/util/internal/NetworkUtil.java (revision a13b55e4ea443bbd6f39edbaa3cc1d73ef8c691f)
+++ b/src/main/java/com/github/f4b6a3/uuid/util/internal/NetworkUtil.java (date 1643102865684)
@@ -193,8 +193,10 @@
// try to find the network interface for the host name
ip = InetAddress.getByName(hostname());
+ // sometimes ip would be localhost ip (127.0.0.1) for normal hostname (e.g. andrey-amd)
ni = NetworkInterface.getByInetAddress(ip);
- if (acceptable(ni)) {
+ // ni would be null for localhost ip (127.0.0.1)
+ if (ni != null && acceptable(ni)) {
nic = ni;
return nic;
}
@@ -225,7 +227,8 @@
*/
private static synchronized boolean acceptable(NetworkInterface ni) {
try {
- if (ni != null && ni.isUp() && !ni.isLoopback() && !ni.isVirtual()) {
+ // isVirtual() returns false and getHardwareAddress() returns null for (at least some) openconnect interfaces
+ if (ni != null && ni.isUp() && !ni.isLoopback() && !ni.isVirtual() && ni.getHardwareAddress() != null) {
return true;
}
} catch (SocketException | NullPointerException e) {
On my machine
InetAddress.getByName(hostname())
(inNetworkUtil::nic
) returns ipv4 loopback address (127.0.0.1). (this happens only with virtual interfaces from openconnect up)It result in NPE in all mac addr using functionality - e.g. see stack.txt
This seem like regression, in 4.1.3 this functionality works fine.
My ugly workaround
Index: src/main/java/com/github/f4b6a3/uuid/util/internal/NetworkUtil.java =================================================================== diff --git a/src/main/java/com/github/f4b6a3/uuid/util/internal/NetworkUtil.java b/src/main/java/com/github/f4b6a3/uuid/util/internal/NetworkUtil.java --- a/src/main/java/com/github/f4b6a3/uuid/util/internal/NetworkUtil.java (revision a13b55e4ea443bbd6f39edbaa3cc1d73ef8c691f) +++ b/src/main/java/com/github/f4b6a3/uuid/util/internal/NetworkUtil.java (date 1643102865684) @@ -193,8 +193,10 @@ // try to find the network interface for the host name ip = InetAddress.getByName(hostname()); + // sometimes ip would be localhost ip (127.0.0.1) for normal hostname (e.g. andrey-amd) ni = NetworkInterface.getByInetAddress(ip); - if (acceptable(ni)) { + // ni would be null for localhost ip (127.0.0.1) + if (ni != null && acceptable(ni)) { nic = ni; return nic; } @@ -225,7 +227,8 @@ */ private static synchronized boolean acceptable(NetworkInterface ni) { try { - if (ni != null && ni.isUp() && !ni.isLoopback() && !ni.isVirtual()) { + // isVirtual() returns false and getHardwareAddress() returns null for (at least some) openconnect interfaces + if (ni != null && ni.isUp() && !ni.isLoopback() && !ni.isVirtual() && ni.getHardwareAddress() != null) { return true; } } catch (SocketException | NullPointerException e) {