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

@Nullable List and Set initialized as empty become null after Java serialization/deserialization #1295

Closed
RJoker0 opened this issue Apr 29, 2021 · 13 comments
Labels
Milestone

Comments

@RJoker0
Copy link

RJoker0 commented Apr 29, 2021

Good day,
We are using immutables 2.8.2 and realized that if we have a @Nullable Set or List fields which are initialized with an empty collection then after Java serialization/deserialization they become nulls.
At the same time, @Nullable Collection fields remain empty collections what I consider expected behavior.

This happens because the generated code is different by some reason between List/Set and Collection fields in the generated SerialForm nested class:

if (instance.collection() != null) {
    names.add("collection");
    values.add(instance.collection());
  }

  if (instance.set() == null) {
    names.add("set");
    values.add(null);
  } else if (!instance.set().isEmpty()) {
    names.add("set");
    values.add(instance.set().toArray());
  }

  if (instance.list() == null) {
    names.add("list");
    values.add(null);
  } else if (!instance.list().isEmpty()) {
    names.add("list");
    values.add(instance.list().toArray());
  }

Would it be possible to change Set and List behavior to the same as for Collections.

Thanks in advance!
immutables-sample.zip

@elucash
Copy link
Member

elucash commented May 9, 2021

will look into that, thank you. I think that code is not completely wrong for being not the same for regular collections (Collection attributes are not recognized as "collections" at all for being too abstract, there's an obscure note about that in collection section in the user guide), but it's definitely not right either, as nullable collection should support null. It could be there are hard to "fix" or intentional limitations for nullable collections in general, will see.

@RJoker0
Copy link
Author

RJoker0 commented May 10, 2021

Thank you, Eugene. 

Maybe just a few words about our use-case: we use generated "request objects" to search for some domain entities (ex. devices). "Request objects" contain all the possible criteria, ex. names, types, locations, etc., which are collections.

We need to distinguish two cases:

  • no criterion provided at all (ex. no types) - this means that we should ignore this criterion completely while searching (we use null Set to represent this)
  • empty criterion provided (ex. empty collection of types) - this means that by some reason a client has given to us no acceptable values (we use empty Set to represent this). Yes, in this case nothing will be found and returned to the client - client side could programmatically compose those criteria and not even realize that some criteria are empty.

Cheers
Roman

@RJoker0
Copy link
Author

RJoker0 commented May 28, 2021

Dear Eugene,
is there any news regarding this problem?
Thanks!
Roman

@elucash
Copy link
Member

elucash commented May 29, 2021

Thanks for reminding, seems like I found the solution, yet was a bit puzzling to figure out where the logical mistake was. I'm merging to master, will release in beta3 in 1-2 days

@RJoker0
Copy link
Author

RJoker0 commented May 30, 2021 via email

@RJoker0
Copy link
Author

RJoker0 commented Jun 17, 2021

Dear Eugene,
when do you plan to release the fix?
Thanks!
Roman

@elucash
Copy link
Member

elucash commented Jun 19, 2021

Hi Roman, only now I've managed to return to this, released in 2.9.0-beta3

@RJoker0
Copy link
Author

RJoker0 commented Jul 1, 2021

Thank you very much, Eugene!
2.9.0-beta3 works for me.
When do you plan to make it proper 2.9.0 release?
Cheers
Roman

@asereda-gs
Copy link
Member

We're planning to release 2.9.0 within couple of weeks

@RJoker0
Copy link
Author

RJoker0 commented Jan 13, 2022

Dear @elucash and @asereda-gs ,
2.9.0 is not yet released, right?
When do you plan to release it?
Thanks!
Roman

@elucash
Copy link
Member

elucash commented Jan 14, 2022

@RJoker0 I'm very sorry for the seemingly endless delays, we had extremely small amount of time that we could dedicate to that in the light of some hard to troubleshoot issues. I've carved some time for the last ditch effort to address known issues with the goal to release with whatever remains. Wish me good luck tonight :)

@RJoker0
Copy link
Author

RJoker0 commented Jan 14, 2022 via email

@elucash elucash added this to the 2.9.0 milestone Jan 19, 2022
@elucash elucash added the bug label Jan 19, 2022
@elucash
Copy link
Member

elucash commented Jan 19, 2022

released in 2.9.0 at last

@elucash elucash closed this as completed Jan 19, 2022
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

3 participants