twilio / authy-java

Java Client for Twilio Authy Two-Factor Authentication (2FA) API
https://www.twilio.com/docs/authy/api
MIT License
65 stars 46 forks source link

NullPointerException in version 1.2.0 (com.authy.api.Resource.java) #30

Closed tpthaler closed 7 years ago

tpthaler commented 7 years ago

` StringBuilder e = new StringBuilder(); if(method.equals("GET")) { e.append(this.prepareGet(data)); }

        URL url = new URL(this.apiUri + path + e.toString());
        HttpURLConnection connection = this.createConnection(url, method, options);
        connection.setRequestProperty("X-Authy-API-Key", this.apiKey);
        if(data.toMap().containsKey("api_key")) {//THROWS A NULL POINTER EXCEPTION
            LOGGER.log(Level.WARNING, "Found \'api_key\' as a parameter, please remove it, Authy-Java already handles the\'api_key\' for you.");
        }

        if(method.equals("POST") || method.equals("PUT")) {
            if(this.isJSON) {
                this.writeJson(connection, data);
            } else {
                this.writeXml(connection, data);
            }
        }

        this.status = connection.getResponseCode();
        answer = this.getResponse(connection);
    } catch (SSLHandshakeException var9) {
        System.err.println("SSL verification is failing. This might be because of an attack. Contact support@authy.com");
    } catch (Exception var10) {
        var10.printStackTrace();
    }

    return answer;
}

`

This line of code is throwing a NPE when trying to create a user, using your documented process (the createUser line below works fine in version 1.1.0):

` User user = users.createUser("new_user@email.com", "405-342-5699", "57");

//eventually calls this which is what blows up as data = null if(data.toMap().containsKey("api_key")) { `

vargasx commented 7 years ago

@tpthaler looks like it is working now