On Sep 16, 2013, at 10:50 AM, Doug Lea <d...@cs.oswego.edu> wrote: > try { > Enumeration<NetworkInterface> ifcs = > NetworkInterface.getNetworkInterfaces(); > boolean retry = false; // retry once if getHardwareAddress is null > while (ifcs.hasMoreElements()) { > NetworkInterface ifc = ifcs.nextElement(); > byte[] bs = ifc.getHardwareAddress(); > if (bs != null) { > for (int i = 0; i < 8 && i < bs.length; ++i) > h = (h << 8) ^ bs[i]; > break; > } > else if (!retry) > retry = true; > else > break; > } > } catch (Exception ignore) { > }
This retry logic seems a bit convoluted; how about: try { Enumeration<NetworkInterface> ifcs = NetworkInterface.getNetworkInterfaces(); if (ifcs.hasMoreElements()) { byte[] bs = ifcs.nextElement().getHardwareAddress(); if (bs == null && ifcs.hasMoreElements()) { // try up to two bs = ifcs.nextElement().getHardwareAddress(); } if (bs != null) { for (int i = 0; i < 8 && i < bs.length; ++i) h = (h << 8) ^ bs[i]; break; } } } catch (Exception ignore) { } ?