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

NullPointerException when using ToBuilder and Singular on List-based Property #1483

Closed
HartmutLuttermann opened this issue Oct 4, 2017 · 3 comments

Comments

@HartmutLuttermann
Copy link

Having following class definition

@Value
@Builder(toBuilder = true)
public class ValueObject{

    @Singular(value = "value")
    private List<String> values;
}

and using following statement

new ValueObject(null).toBuilder();

throws NullPointerException in method toBuilder()

java.lang.NullPointerException
	at java.util.ArrayList.addAll(ArrayList.java:577)
	at <package>.ValueObject$ValueObjectBuilder.values(ValueObject.java:10)

In my opinion this is an error in the implementation of the setter-method of the ValueObjectBuilder. A non-null-check only will fix this:

public ValueObject.ValueObjectBuilder values(final Collection<? extends String> values) {
            if (this.values == null) this.values = new ArrayList<String>();
           // added: check on non-null values
            if (values != null)
                  this.values.addAll(values);
            return this;
        }
@brokenbeatnik
Copy link

I'm also seeing this issue.

@oyku-gencay
Copy link

oyku-gencay commented Jan 16, 2018

Same here. I've got a private constructor annotated with Builder with toBuilder true.

@rzwitserloot
Copy link
Collaborator

Duplicate of #1324 – the suggested fix is not acceptable; calling .foos(null) silently doing nothing is not a sound plan. A fix for this problem is forthcoming.

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

4 participants