Permalink
Browse files

fix #781.

Wrapping a Java Document in a XmlDocument didn't initialize the instance
varaibles which caused the Xml::Node::parse method to throw an error when
trying to access the errors iv.
  • Loading branch information...
1 parent 557e674 commit b5c1d9df8b8982b586406bea1779b0dbb8ef9566 @jvshahid jvshahid committed Oct 25, 2012
Showing with 22 additions and 9 deletions.
  1. +1 −0 CHANGELOG.rdoc
  2. +1 −0 ext/java/nokogiri/XmlDocument.java
  3. +20 −9 test/xml/test_document.rb
View
@@ -22,6 +22,7 @@
* JRuby XPath queries for namespaces should not throw exceptions when called twice in a row. #764
* [jruby] More consistent (with libxml2) whitespace formatting when emitting XML (#771)
* JRuby namespaced attributes broken when appending raw xml to builder. #770
+ * JRuby Nokogiri::XML::Document#wrap raises undefined method `length' for nil:NilClass when trying to << to a node. #781
== 1.5.5 / 2012-06-24
@@ -535,6 +535,7 @@ public void accept(ThreadContext context, SaveContextVisitor visitor) {
@JRubyMethod(meta=true)
public static IRubyObject wrapJavaDocument(ThreadContext context, IRubyObject klazz, IRubyObject arg) {
XmlDocument xmlDocument = (XmlDocument) NokogiriService.XML_DOCUMENT_ALLOCATOR.allocate(context.getRuntime(), getNokogiriClass(context.getRuntime(), "Nokogiri::XML::Document"));
+ RuntimeHelpers.invoke(context, xmlDocument, "initialize");
Document document = (Document)arg.toJava(Document.class);
xmlDocument.setDocumentNode(context, document);
return xmlDocument;
View
@@ -727,26 +727,37 @@ def awesome!
assert @xml.children.respond_to?(:awesome!)
end
- def test_java_integration
- if Nokogiri.jruby?
+ if Nokogiri.jruby?
+ def wrap_java_document
require 'java'
factory = javax.xml.parsers.DocumentBuilderFactory.newInstance
builder = factory.newDocumentBuilder
document = builder.newDocument
root = document.createElement("foo")
document.appendChild(root)
- noko_doc = Nokogiri::XML::Document.wrap(document)
- assert_equal 'foo', noko_doc.root.name
+ Nokogiri::XML::Document.wrap(document)
+ end
+ end
+
+ def test_java_integration
+ skip("Ruby doesn't have the wrap method") unless Nokogiri.jruby?
+ noko_doc = wrap_java_document
+ assert_equal 'foo', noko_doc.root.name
- noko_doc = Nokogiri::XML(<<eoxml)
+ noko_doc = Nokogiri::XML(<<eoxml)
<foo xmlns='hello'>
<bar xmlns:foo='world' />
</foo>
eoxml
- dom = noko_doc.to_java
- assert dom.kind_of? org.w3c.dom.Document
- assert_equal 'foo', dom.getDocumentElement().getTagName()
- end
+ dom = noko_doc.to_java
+ assert dom.kind_of? org.w3c.dom.Document
+ assert_equal 'foo', dom.getDocumentElement().getTagName()
+ end
+
+ def test_add_child
+ skip("Ruby doesn't have the wrap method") unless Nokogiri.jruby?
+ doc = wrap_java_document
+ doc.root.add_child "<bar />"
end
end
end

0 comments on commit b5c1d9d

Please sign in to comment.