Repository: wicket Updated Branches: refs/heads/master 988f0fa57 -> bcea89fc8
WICKET-5751 NullPointerException in IntHashMap WICKET-5584 DiskDataStore error Initialize modCount in readObject() Project: http://git-wip-us.apache.org/repos/asf/wicket/repo Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/bcea89fc Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/bcea89fc Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/bcea89fc Branch: refs/heads/master Commit: bcea89fc8a196d2e1ebdcecf9c81298a06b4f5cb Parents: 988f0fa Author: Martin Tzvetanov Grigorov <[email protected]> Authored: Tue Nov 18 09:40:17 2014 +0200 Committer: Martin Tzvetanov Grigorov <[email protected]> Committed: Tue Nov 18 09:40:17 2014 +0200 ---------------------------------------------------------------------- .../wicket/util/collections/IntHashMap.java | 2 + .../wicket/util/collections/IntHashMapTest.java | 61 ++++++++++++++++++++ 2 files changed, 63 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/wicket/blob/bcea89fc/wicket-util/src/main/java/org/apache/wicket/util/collections/IntHashMap.java ---------------------------------------------------------------------- diff --git a/wicket-util/src/main/java/org/apache/wicket/util/collections/IntHashMap.java b/wicket-util/src/main/java/org/apache/wicket/util/collections/IntHashMap.java index 7b377fc..7a8d180 100644 --- a/wicket-util/src/main/java/org/apache/wicket/util/collections/IntHashMap.java +++ b/wicket-util/src/main/java/org/apache/wicket/util/collections/IntHashMap.java @@ -1145,6 +1145,8 @@ public class IntHashMap<V> implements Cloneable, Serializable private void readObject(final java.io.ObjectInputStream s) throws IOException, ClassNotFoundException { + modCount = new AtomicInteger(0); + // Read in the threshold, loadfactor, and any hidden stuff s.defaultReadObject(); http://git-wip-us.apache.org/repos/asf/wicket/blob/bcea89fc/wicket-util/src/test/java/org/apache/wicket/util/collections/IntHashMapTest.java ---------------------------------------------------------------------- diff --git a/wicket-util/src/test/java/org/apache/wicket/util/collections/IntHashMapTest.java b/wicket-util/src/test/java/org/apache/wicket/util/collections/IntHashMapTest.java new file mode 100644 index 0000000..f38ee54 --- /dev/null +++ b/wicket-util/src/test/java/org/apache/wicket/util/collections/IntHashMapTest.java @@ -0,0 +1,61 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.wicket.util.collections; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.notNullValue; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.util.Iterator; + +import org.apache.wicket.util.io.ByteArrayOutputStream; +import org.junit.Assert; +import org.junit.Test; + +public class IntHashMapTest extends Assert +{ + + @Test + public void serialize() throws IOException, ClassNotFoundException + { + IntHashMap<String> map = new IntHashMap<>(); + map.put(1, "one"); + map.put(2, "two"); + + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + ObjectOutputStream oos = new ObjectOutputStream(baos); + oos.writeObject(map); + + byte[] serialized = baos.toByteArray(); + ByteArrayInputStream bais = new ByteArrayInputStream(serialized); + ObjectInputStream ois = new ObjectInputStream(bais); + IntHashMap<String> deserialized = (IntHashMap<String>) ois.readObject(); + assertThat(deserialized, is(notNullValue())); + assertThat(deserialized.get(1), is(equalTo("one"))); + assertThat(deserialized.get(2), is(equalTo("two"))); + + // WICKET-5584 + deserialized.put(3, "three"); + + // WICKET-5751 + deserialized.entrySet().iterator(); + } +}
