diff --git a/ext/java/nokogiri/internals/HtmlDomParserContext.java b/ext/java/nokogiri/internals/HtmlDomParserContext.java
index 71a2bacdefd..69c1d47d66c 100644
--- a/ext/java/nokogiri/internals/HtmlDomParserContext.java
+++ b/ext/java/nokogiri/internals/HtmlDomParserContext.java
@@ -52,6 +52,7 @@
import org.jruby.Ruby;
import org.jruby.RubyClass;
import org.jruby.runtime.ThreadContext;
+import org.jruby.runtime.Helpers;
import org.jruby.runtime.builtin.IRubyObject;
import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
@@ -133,6 +134,8 @@ public XmlDocument parse(ThreadContext context, RubyClass klass, IRubyObject url
protected XmlDocument wrapDocument(ThreadContext context, RubyClass klass, Document document) {
HtmlDocument htmlDocument = new HtmlDocument(context.runtime, klass, document);
htmlDocument.setDocumentNode(context.runtime, document);
+ Helpers.invoke(context, htmlDocument, "initialize");
+
if (ruby_encoding.isNil()) {
// ruby_encoding might have detected by HtmlDocument::EncodingReader
if (detected_encoding != null && !detected_encoding.isNil()) {
diff --git a/ext/java/nokogiri/internals/XmlDomParserContext.java b/ext/java/nokogiri/internals/XmlDomParserContext.java
index d400faae0c8..d993047fc77 100644
--- a/ext/java/nokogiri/internals/XmlDomParserContext.java
+++ b/ext/java/nokogiri/internals/XmlDomParserContext.java
@@ -46,6 +46,7 @@
import org.jruby.RubyFixnum;
import org.jruby.exceptions.RaiseException;
import org.jruby.runtime.ThreadContext;
+import org.jruby.runtime.Helpers;
import org.jruby.runtime.builtin.IRubyObject;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
@@ -213,6 +214,7 @@ private XmlDocument getInterruptedOrNewXmlDocument(ThreadContext context, RubyCl
*/
protected XmlDocument wrapDocument(ThreadContext context, RubyClass klass, Document doc) {
XmlDocument xmlDocument = new XmlDocument(context.runtime, klass, doc);
+ Helpers.invoke(context, xmlDocument, "initialize");
xmlDocument.setEncoding(ruby_encoding);
if (options.dtdLoad) {