Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8042416

X11GraphicsEnvironment.isDisplayLocal() throws NoSuchElementException if DISPLAY host has more IP addresses than a local interface

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 9
    • None
    • client-libs
    • b15

      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;
                                  }
                              }
                          }
                      }

            simonis Volker Simonis
            simonis Volker Simonis
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: