Hi Max, I don't see any particular reason for this. Maybe it's just a "precaution". It seems to me it's the only field of the URL class set directly (without setter) from an outside.
Does it hurt performance a lot? In what cases? -Pavel > On 25 Nov 2014, at 12:02, Wang Weijun <weijun.w...@oracle.com> wrote: > > I am benchmarking security manager and notice this > > protected synchronized InetAddress getHostAddress(URL u) { > if (u.hostAddress != null) > return u.hostAddress; > > String host = u.getHost(); > if (host == null || host.equals("")) { > return null; > } else { > try { > u.hostAddress = InetAddress.getByName(host); > } catch (UnknownHostException ex) { > return null; > } catch (SecurityException se) { > return null; > } > } > return u.hostAddress; > } > > Is there any reason why the method is synchronized? Why not simply > "synchronized (u)"? > > Thanks > Max >