diff --git a/test/com/esotericsoftware/kryo/MapSerializerTest.java b/test/com/esotericsoftware/kryo/MapSerializerTest.java index 4b6d44b9f..4f829e951 100644 --- a/test/com/esotericsoftware/kryo/MapSerializerTest.java +++ b/test/com/esotericsoftware/kryo/MapSerializerTest.java @@ -15,13 +15,17 @@ * SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ + package com.esotericsoftware.kryo; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.util.ArrayList; import java.util.Comparator; import java.util.HashMap; import java.util.LinkedHashMap; +import java.util.List; import java.util.Map; import java.util.Random; import java.util.TreeMap; @@ -167,7 +171,32 @@ public void testTreeMapWithReferences () { map.put("4", 44); roundTrip(29, 43, map); } - + + public void testSerializingMapAfterDeserializingMultipleReferencesToSameMap() throws Exception { + Kryo kryo = new Kryo(); + Output output = new Output(4096); + + kryo.writeClassAndObject(output, new HasMultipleReferenceToSameMap()); + kryo.readClassAndObject(new Input(new ByteArrayInputStream(output.getBuffer()))); + output.clear(); + + Map> mapOfLists = new HashMap>(); + mapOfLists.put(1, new ArrayList()); + kryo.writeClassAndObject(output, mapOfLists); + + @SuppressWarnings("unchecked") + Map> deserializedMap = + (Map>) kryo.readClassAndObject(new Input(new ByteArrayInputStream(output.getBuffer()))); + assertEquals(1, deserializedMap.size()); + } + + @SuppressWarnings("unused") + static class HasMultipleReferenceToSameMap { + private Map mapOne = new HashMap(); + private Map mapTwo = this.mapOne; + } + + static public class HasGenerics { public HashMap map = new HashMap(); public HashMap map2 = new HashMap(); @@ -195,4 +224,4 @@ public TreeMapSubclass(Comparator comparator) { super(comparator); } } -} +}