package com.topsy.jmxproxy.jmx;

import com.fasterxml.jackson.annotation.JsonProperty;

import org.hibernate.validator.constraints.NotEmpty;

public class ConnectionCredentials {
    @NotEmpty
    @JsonProperty
    private final String username;

    @NotEmpty
    @JsonProperty
    private final String password;

    public ConnectionCredentials(@JsonProperty("username") String username, @JsonProperty("password") String password) {
        this.username = username;
        this.password = password;
    }

    public String getUsername() {
        return username;
    }

    public String getPassword() {
        return password;
    }

    @Override
    public boolean equals(Object peer) {
        ConnectionCredentials auth = (ConnectionCredentials) peer;

        return username == auth.getUsername() && password == auth.getPassword();
    }
}

package com.topsy.jmxproxy.jmx;

import com.fasterxml.jackson.annotation.JsonProperty;

import org.hibernate.validator.constraints.NotEmpty;

public class ConnectionCredentials {
    @NotEmpty
    @JsonProperty
    private final String username;

    @NotEmpty
    @JsonProperty
    private final String password;

    public ConnectionCredentials(@JsonProperty("username") String username, @JsonProperty("password") String password) {
        this.username = username;
        this.password = password;
    }

    public String getUsername() {
        return username;
    }

    public String getPassword() {
        return password;
    }

    @Override
    public boolean equals(Object peer) {
        ConnectionCredentials auth = (ConnectionCredentials) peer;

        return auth != null && username == auth.getUsername() && password == auth.getPassword();
    }
}

Handle null credentials object in the comparison.
Handle null credentials object in the comparison.
