@Override
    public InetSocketAddress resolve(String name, boolean ipv6, boolean local)
    {
        //  Find the ':' at end that separates address from the port number.
        int delimiter = name.lastIndexOf(':');
        if (delimiter < 0) {
            throw new IllegalArgumentException(name);
        }

        //  Separate the address/port.
        String addrStr = name.substring(0, delimiter);
        String portStr = name.substring(delimiter + 1);

        //  Remove square brackets around the address, if any.
        if (addrStr.length() >= 2 && addrStr.charAt(0) == '[' && addrStr.charAt(addrStr.length() - 1) == ']') {
            addrStr = addrStr.substring(1, addrStr.length() - 1);
        }

        int port;
        //  Allow 0 specifically, to detect invalid port error in atoi if not
        if (portStr.equals("*") || portStr.equals("0")) {
            //  Resolve wildcard to 0 to allow autoselection of port
            port = 0;
        }
        else {
            //  Parse the port number (0 is not a valid port).
            port = Integer.parseInt(portStr);
            if (port == 0) {
                throw new IllegalArgumentException(name);
            }
        }

        InetAddress addrNet = null;

        // '*' as unspecified address is not accepted in Java
        // '::' for IPv6 is accepted
        if (addrStr.equals("*")) {
            addrStr = ipv6 ? "::" : "0.0.0.0";
        }

        try {
            InetAddress[] addresses = InetAddress.getAllByName(addrStr);
            if (ipv6) {
                // prefer IPv6: return the first ipv6 or the first value if not found
                for (InetAddress addr : addresses) {
                    if (addr instanceof Inet6Address) {
                        addrNet = addr;
                        break;
                    }
                }
                if (addrNet == null) {
                    addrNet = addresses[0];
                }
            }
            else {
                for (InetAddress addr : addresses) {
                    if (addr instanceof Inet4Address) {
                        addrNet = addr;
                        break;
                    }
                }
            }
        }
        catch (UnknownHostException e) {
            throw new ZMQException(e.getMessage(), ZError.EADDRNOTAVAIL, e);
        }

        if (addrNet == null) {
            throw new ZMQException(addrStr + " not found matching IPv4/IPv6 settings", ZError.EADDRNOTAVAIL);
        }

        return new InetSocketAddress(addrNet, port);
    }
@Test
    public void testBad()
    {
        try {
            Address addr = new Address(NetProtocol.tcp, "ggglocalhostxxx.google.com:80");
            addr.resolve(true);
            addr.resolved();
            Assert.fail();
        }
        catch (ZMQException e) {
            Assert.assertEquals(ZError.EADDRNOTAVAIL, e.getErrorCode());
            Assert.assertEquals(e.getCause().getMessage(), e.getMessage());
        }
    }