Monday, March 16, 2015

MalformedURLException

java.net.MalformedURLException

MalformedURLException is described in the javadoc comments as:

Thrown to indicate that a malformed URL has occurred. Either no legal protocol could be found in a specification string or the string could not be parsed.
author: Arthur van Hoff version: 1.16, 12/19/03 since: JDK1.0

Where is this exception thrown?

Following, is a list of exception messages cross-referenced to the source code responsible for throwing them. Click on the method link to view the code and see how the exception is thrown.

How is this exception thrown?

The following sub-sections identify where this exception is thrown, and how (or why) the code is throwing the exception.

Any source code quoted in this section is subject to the Java Research License unless stated otherwise.

javax.management.remote.rmi.RMIConnector.findRMIServer(JMXServiceURL, Map)

private RMIServer findRMIServer(JMXServiceURL directoryURL, Map environment) throws NamingException, IOException {
    final boolean isIiop = RMIConnectorServer.isIiopURL(directoryURL, true);
    if (isIiop) {
        environment.put(EnvHelp.DEFAULT_ORB, resolveOrb(environment));
    }
    String path = directoryURL.getURLPath();
    if (path.startsWith('/jndi/')) return findRMIServerJNDI(path.substring(6), environment, isIiop); else if (path.startsWith('/stub/')) return findRMIServerJRMP(path.substring(6), environment, isIiop); else if (path.startsWith('/ior/')) return findRMIServerIIOP(path.substring(5), environment, isIiop); else {
        final String msg = 'URL path must begin with /jndi/ or /stub/ ' + 'or /ior/: ' + path;
        throw new MalformedURLException(msg);
    }
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

javax.management.remote.rmi.RMIConnector.findRMIServerJRMP(String, Map, boolean)

private RMIServer findRMIServerJRMP(String base64, Map env, boolean isIiop) throws IOException {
    final byte[] serialized;
    try {
        serialized = base64ToByteArray(base64);
    } catch (IllegalArgumentException e) {
        throw new MalformedURLException('Bad BASE64 encoding: ' + e.getMessage());
    }
    final ByteArrayInputStream bin = new ByteArrayInputStream(serialized);
    final ClassLoader loader = EnvHelp.resolveClientClassLoader(env);
    final ObjectInputStream oin = (loader == null) ? new ObjectInputStream(bin) : new ObjectInputStreamWithLoader(bin, loader);
    final Object stub;
    try {
        stub = oin.readObject();
    } catch (ClassNotFoundException e) {
        throw new MalformedURLException('Class not found: ' + e);
    }
    return (RMIServer) PortableRemoteObject.narrow(stub, RMIServer.class);
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

javax.management.remote.JMXServiceURL.validate()

private void validate() throws MalformedURLException {
    final int protoEnd = indexOfFirstNotInSet(protocol, protocolBitSet, 0);
    if (protoEnd == 0 || protoEnd < protocol.length() || !alphaBitSet.get(protocol.charAt(0))) {
        throw new MalformedURLException('Missing or invalid protocol ' + 'name: \'' + protocol + '\'');
    }
    validateHost();
    if (port < 0) throw new MalformedURLException('Bad port: ' + port);
    if (urlPath.length() > 0) {
        if (!urlPath.startsWith('/') && !urlPath.startsWith(';')) throw new MalformedURLException('Bad URL path: ' + urlPath);
    }
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

javax.management.remote.JMXServiceURL.validateHost(String)

private static void validateHost(String h) throws MalformedURLException {
    if (isNumericIPv6Address(h)) {
        try {
            InetAddress.getByName(h);
        } catch (Exception e) {
            MalformedURLException bad = new MalformedURLException('Bad IPv6 address: ' + h);
            EnvHelp.initCause(bad, e);
            throw bad;
        }
    } else {
        final int hostLen = h.length();
        char lastc = '.';
        boolean sawDot = false;
        char componentStart = 0;
        loop: for (int i = 0; i < hostLen; i++) {
            char c = h.charAt(i);
            boolean isAlphaNumeric = alphaNumericBitSet.get(c);
            if (lastc == '.') componentStart = c;
            if (isAlphaNumeric) lastc = 'a'; else if (c == '-') {
                if (lastc == '.') break;
                lastc = '-';
            } else if (c == '.') {
                sawDot = true;
                if (lastc != 'a') break;
                lastc = '.';
            } else {
                lastc = '.';
                break;
            }
        }
        try {
            if (lastc != 'a') throw randomException;
            if (sawDot && !alphaBitSet.get(componentStart)) {
                StringTokenizer tok = new StringTokenizer(h, '.', true);
                for (int i = 0; i < 4; i++) {
                    String ns = tok.nextToken();
                    int n = Integer.parseInt(ns);
                    if (n < 0 || n > 255) throw randomException;
                    if (i < 3 && !tok.nextToken().equals('.')) throw randomException;
                }
                if (tok.hasMoreTokens()) throw randomException;
            }
        } catch (Exception e) {
            throw new MalformedURLException('Bad host: \'' + h + '\'');
        }
    }
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

javax.management.remote.JMXServiceURL.validateHost()

private void validateHost() throws MalformedURLException {
    if (host.length() == 0) {
        if (port != 0) {
            throw new MalformedURLException('Cannot give port number ' + 'without host name');
        }
        return;
    }
    validateHost(host);
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

javax.management.remote.rmi.RMIConnectorServer.isIiopURL(JMXServiceURL, boolean)

static boolean isIiopURL(JMXServiceURL directoryURL, boolean strict) throws MalformedURLException {
    String protocol = directoryURL.getProtocol();
    if (protocol.equals('rmi')) return false; else if (protocol.equals('iiop')) return true; else if (strict) {
        throw new MalformedURLException('URL must have protocol ' + '\'rmi\' or \'iiop\': \'' + protocol + '\'');
    }
    return false;
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

java.rmi.Naming.parseURL(String)

/**
     * Dissect Naming URL strings to obtain referenced host, port and
     * object name.
     * @return an object which contains each of the above
     * components.
     * @exception MalformedURLException if given url string is malformed
     */
private static ParsedNamingURL parseURL(String str) throws MalformedURLException {
    try {
        URI uri = new URI(str);
        if (uri.getFragment() != null) {
            throw new MalformedURLException('invalid character, '#', in URL name: ' + str);
        } else if (uri.getQuery() != null) {
            throw new MalformedURLException('invalid character, '?', in URL name: ' + str);
        } else if (uri.getUserInfo() != null) {
            throw new MalformedURLException('invalid character, '@', in URL host: ' + str);
        }
        String scheme = uri.getScheme();
        if (scheme != null && !scheme.equals('rmi')) {
            throw new MalformedURLException('invalid URL scheme: ' + str);
        }
        String name = uri.getPath();
        if (name != null) {
            if (name.startsWith('/')) {
                name = name.substring(1);
            }
            if (name.length() == 0) {
                name = null;
            }
        }
        String host = uri.getHost();
        if (host == null) {
            host = '';
            if (uri.getPort() == -1) {
                String authority = uri.getAuthority();
                if (authority != null && authority.startsWith(':')) {
                    authority = 'localhost' + authority;
                    uri = new URI(null, authority, null, null, null);
                }
            }
        }
        int port = uri.getPort();
        if (port == -1) {
            port = Registry.REGISTRY_PORT;
        }
        return new ParsedNamingURL(host, port, name);
    } catch (URISyntaxException ex) {
        throw (MalformedURLException) new MalformedURLException('invalid URL string: ' + str).initCause(ex);
    }
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

java.net.JarURLConnection.parseSpecs(URL)

private void parseSpecs(URL url) throws MalformedURLException {
    String spec = url.getFile();
    int separator = spec.indexOf('!');
    if (separator == -1) {
        throw new MalformedURLException('no ! found in url spec:' + spec);
    }
    jarFileURL = new URL(spec.substring(0, separator++));
    entryName = null;
    if (++separator != spec.length()) {
        entryName = spec.substring(separator, spec.length());
        entryName = ParseUtil.decode(entryName);
    }
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

No comments:

Post a Comment