hprose / hprose-java

Hprose is a cross-language RPC. This project is Hprose 2.0 for Java
MIT License
550 stars 187 forks source link

null pointer exception #34

Closed chenbihuan closed 6 years ago

chenbihuan commented 6 years ago

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);
    }
andot commented 6 years ago

Thank you.