Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Password class to properly handle null #655

Closed
ctron opened this issue Oct 19, 2016 · 5 comments
Closed

Fix Password class to properly handle null #655

ctron opened this issue Oct 19, 2016 · 5 comments

Comments

@ctron
Copy link
Contributor

ctron commented Oct 19, 2016

IMHO the Password class should be refactored as follows:

public class Password {

    private char[] m_password;

    private Password(String password) {
        super();
        if (password != null) {
            this.m_password = password.toCharArray();
        }
    }

    private Password(char[] password) {
        super();
        this.m_password = password;
    }

    public char[] getPassword() {
        return this.m_password;
    }

    @Override
    public String toString() {
        return new String(this.m_password);
    }

    public static Password valueOf (String password)  {
       if ( password == null ) return null;
       return new Password ( password );
    }

    public static Password valueOf (char [] password)  {
       if ( password == null ) return null;
       return new Password ( password );
    }
}

This would allow for easy null handling. Right now lots of places in Kura just pass "null" to the constructor, which may result in a NPE later on calling toString();

@MMaiero MMaiero added this to the KURA-2.2.0 milestone Nov 2, 2016
@MMaiero MMaiero removed this from the KURA-3.0.0 milestone Apr 24, 2017
@cdealti
Copy link
Contributor

cdealti commented Feb 15, 2018

@ctron don't you think we should not instantiate an null Password instead?

@ctron
Copy link
Contributor Author

ctron commented Feb 15, 2018

don't you think we should not instantiate an null Password instead?

What do you mean by that? If the password is null it will not create a new instance of Password but return null instead.

@cdealti
Copy link
Contributor

cdealti commented Feb 15, 2018

I mean changing Kura checking is password is not null before creating a Password:
if (password != NULL) { p = new Password(password); }
But if you think otherwise, please go ahead submitting your changes above. It looks you only added new methods and the change looks backward compatible for the API consumers and I believe there are classes extending Password (@ProviderType).

Copy link
Contributor

This issue is stale because it has been open for 60 days with no activity.

@github-actions github-actions bot added the Stale label Nov 13, 2023
Copy link
Contributor

This issue was closed because it has been inactive for 14 days since being marked as stale.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants