hprose / hprose-java

Hprose is a cross-language RPC. This project is Hprose 2.0 for Java

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

null pointer exception

chenbihuan opened this issue · comments

Hi,

The following two methods may receive a uri with undefined scheme. Thus getScheme() may return null, which causes a null pointer exception. The similar problem may arise in hprose.client.HproseTcpClient. Although it is clearly stated in the wiki that only http and tcp are supported, it is better to add such null checks.

public static HproseClient hprose.client.HproseHttpClient.create(String uri, HproseMode mode) throws IOException, URISyntaxException {
        String scheme = (new URI(uri)).getScheme().toLowerCase();
        if (!scheme.equals("http") && !scheme.equals("https")) {
            throw new HproseException("This client doesn't support " + scheme + " scheme.");
        }
        return new HproseHttpClient(uri, mode);
}

public static HproseClient hprose.client.HproseHttpClient.create(String[] uris, HproseMode mode) throws IOException, URISyntaxException {
        for (int i = 0, n = uris.length; i < n; ++i) {
            String scheme = (new URI(uris[i])).getScheme().toLowerCase();
            if (!scheme.equals("http") && !scheme.equals("https")) {
                throw new HproseException("This client doesn't support " + scheme + " scheme.");
            }
        }
        return new HproseHttpClient(uris, mode);
    }

Thank you.