<AWT Dev> RFR(XS): 8042416: X11GraphicsEnvironment.isDisplayLocal() throws NoSuchElementException if DISPLAY host has more IP addresses than a local interface

Alexander Zvegintsev alexander.zvegintsev at oracle.com
Wed May 7 12:28:11 UTC 2014


Hi Volker,

the fix looks fine to me.

P.S. I noticed that there is no cast in the webrev itself, but the 
patch[1] under jdk.changeset link
has it.

[1] http://cr.openjdk.java.net/~simonis/webrevs/8042416/jdk.changeset


Thanks,

Alexander.

On 05/05/2014 10:07 PM, Volker Simonis wrote:
> Hi,
>
> could you please review this tiny fix:
>
> http://cr.openjdk.java.net/~simonis/webrevs/8042416/
> https://bugs.openjdk.java.net/browse/JDK-8042416
>
> X11GraphicsEnvironment.isDisplayLocal() calls
> X11GraphicsEnvironment._isDisplayLocal() whihc in turn iterates over
> all IP addressees of the DISPLAY host and checks if one of them
> corresponds to the IP address of a local network interface:
>
> for (; interfaces.hasMoreElements();) {
>      locals = interfaces.nextElement().getInetAddresses();
>      for (; locals.hasMoreElements();) {
>          for (int i = 0; i < remAddr.length; i++) {
>              if (locals.nextElement().equals(remAddr[i])) {
>                  return Boolean.TRUE;
>              }
>          }
>      }
> }
>
> However it calls locals.nextElement() for each IP address of the
> DISPLAY host so if the DISPLAY host has more IP addresses than one of
> the local network interfaces, the check will unexpectedly throw a
> NoSuchElementException.
>
> The solution is simple - just compare every IP-Address of the DISPLAY
> host against each IP-address of every network interface like so:
>
> for (; interfaces.hasMoreElements();) {
>      locals = interfaces.nextElement().getInetAddresses();
>      for (; locals.hasMoreElements();) {
>          final InetAddress localAddr = locals.nextElement();
>          for (int i = 0; i < remAddr.length; i++) {
>              if (localsAddr.equals(remAddr[i])) {
>                  return Boolean.TRUE;
>              }
>          }
>      }
> }
>
> Thank you and best regards,
> Volker
>
>
> PS: Notice that if we ever want to downport this to jdk8 we need an
> additional cast like so:
>
> final InetAddress localAddr = (InetAddress)locals.nextElement();
>
> unless we also downport "8039642: Fix raw and unchecked warnings in
> sun.awt.*" before this change.



More information about the awt-dev mailing list