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

AbstractContextBuilder.set(Class<T>, T) implementation is weird #112

Open
marschall opened this issue Jan 2, 2019 · 2 comments
Open

AbstractContextBuilder.set(Class<T>, T) implementation is weird #112

marschall opened this issue Jan 2, 2019 · 2 comments
Labels
Milestone

Comments

@marschall
Copy link
Member

I had a look at the implementation of AbstractContextBuilder.set(Class, T) and I'm a bit confused:

    public <T> B set(Class<T> key, T value) {
        B old = set(key.getName(), Objects.requireNonNull(value));
        if (old != null && old.getClass().isAssignableFrom(value.getClass())) {
            return old;
        }
        return (B) this;
    }

It calls #set(String, Object), however this method does not return the old value but this so "old" is a confusing name. Then it makes tests whether "old" (which is this) is a super type of the value class. If it is it returns "old", which is this, otherwise it returns this.

I believe the method should just be:

    public <T> B set(Class<T> key, T value) {
        return set(key.getName(), Objects.requireNonNull(value));
    }
@keilw keilw added the analysis label Jan 31, 2019
@keilw
Copy link
Member

keilw commented Jan 31, 2019

This does not seem to be a showstopper or have significant impact on the outside for users of the API, does it?

@marschall
Copy link
Member Author

No, not at all. It’s just a clean up or code quality thing that affects only the implementation. The behavior users see is exactly the same.

@keilw keilw added this to the .Next milestone Feb 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants