Skip to content

Commit

Permalink
optimize: add null value check for MAC address (apache#6458)
Browse files Browse the repository at this point in the history
  • Loading branch information
bageyang authored Apr 23, 2024
1 parent 314b609 commit aa74ef0
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,10 @@ private long generateWorkerIdBaseOnMac() throws Exception {
NetworkInterface networkInterface = all.nextElement();
boolean isLoopback = networkInterface.isLoopback();
boolean isVirtual = networkInterface.isVirtual();
if (isLoopback || isVirtual) {
byte[] mac = networkInterface.getHardwareAddress();
if (isLoopback || isVirtual || mac == null) {
continue;
}
byte[] mac = networkInterface.getHardwareAddress();
return ((mac[4] & 0B11) << 8) | (mac[5] & 0xFF);
}
throw new RuntimeException("no available mac found");
Expand Down

0 comments on commit aa74ef0

Please sign in to comment.