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

Volker Simonis volker.simonis at gmail.com
Mon May 5 18:07:30 UTC 2014


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