3

Why is this failing? I am comparing the serialized form of an empty HashSet with the serialized form of its clone created by serialization+deserialization.

import org.apache.commons.lang3.SerializationUtils;
import static org.assertj.core.api.Assertions.assertThat;

...

final HashSet<String> hashSet = new HashSet<>();
assertThat(SerializationUtils.serialize(hashSet))
    .containsExactly(SerializationUtils.serialize(SerializationUtils.clone(hashSet)));

AssertionError will be thrown.

Something must be not correctly serialized/deserialized in a HashSet. Do you have any idea, what exactly? I am Using OpenJDK 8.

Sotirios Delimanolis
  • 274,122
  • 60
  • 696
  • 724
Gábor Lipták
  • 9,646
  • 2
  • 59
  • 113
  • just FYI: [What is a raw type and why shouldn't we use it?](https://stackoverflow.com/questions/2770321/what-is-a-raw-type-and-why-shouldnt-we-use-it) – Lino Dec 03 '20 at 13:05
  • @Lino thanks. Yep. But it is not relevant for the question. I add a type for it ;) – Gábor Lipták Dec 03 '20 at 13:19

1 Answers1

1

It has something with loadingFactor. If the Hashset is instantiated like this, then it works:

new HashSet(0,0.75f);
Gábor Lipták
  • 9,646
  • 2
  • 59
  • 113