RFR 8024253: ThreadLocal random can use SecureRandom for the initial seed
Guy Steele
guy.steele at oracle.com
Mon Sep 16 15:10:20 UTC 2013
On Sep 16, 2013, at 10:50 AM, Doug Lea <dl at 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) {
}
?
More information about the core-libs-dev
mailing list