diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 07ca104cfe4..3c2b82135ee 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -8,6 +8,9 @@ + + StaticDomNodeList has to be serializable. + Lambda functions used by Element have to be serializable. diff --git a/src/main/java/com/gargoylesoftware/htmlunit/html/StaticDomNodeList.java b/src/main/java/com/gargoylesoftware/htmlunit/html/StaticDomNodeList.java index c908800b267..ce52fc6c720 100644 --- a/src/main/java/com/gargoylesoftware/htmlunit/html/StaticDomNodeList.java +++ b/src/main/java/com/gargoylesoftware/htmlunit/html/StaticDomNodeList.java @@ -14,6 +14,7 @@ */ package com.gargoylesoftware.htmlunit.html; +import java.io.Serializable; import java.util.AbstractList; import java.util.List; @@ -23,8 +24,9 @@ * An implementation of DomNodeList that is static. * * @author Ahmed Ashour + * @author Ronald Brill */ -class StaticDomNodeList extends AbstractList implements DomNodeList { +class StaticDomNodeList extends AbstractList implements DomNodeList, Serializable { private final List elements_; diff --git a/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlPageTest.java b/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlPageTest.java index 3e78ca3bfe2..68966399fca 100644 --- a/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlPageTest.java +++ b/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlPageTest.java @@ -1344,6 +1344,35 @@ public void serializationLambda() throws Exception { assertEquals("Hello there!", page2.getHtmlElementById("myId").getFirstChild().getNodeValue()); } + /** + * @throws Exception if the test fails + */ + @Test + public void serializationStaticDomNodeList() throws Exception { + final String content = + "\n" + + "
Hello there!
\n" + + "
\n" + + "\n" + + ""; + + final HtmlPage page1 = loadPage(content); + final byte[] bytes = SerializationUtils.serialize(page1); + + final HtmlPage page2 = (HtmlPage) SerializationUtils.deserialize(bytes); + + final Iterator iterator1 = page1.getHtmlElementDescendants().iterator(); + final Iterator iterator2 = page2.getHtmlElementDescendants().iterator(); + while (iterator1.hasNext()) { + assertTrue(iterator2.hasNext()); + final HtmlElement element1 = iterator1.next(); + final HtmlElement element2 = iterator2.next(); + assertEquals(element1.getNodeName(), element2.getNodeName()); + } + assertFalse(iterator2.hasNext()); + assertEquals("Hello there!", page2.getHtmlElementById("myId").getFirstChild().getNodeValue()); + } + /** * Verifies that a cloned HtmlPage has its own "idMap_". * @throws Exception if the test fails