Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RuntimeError when calling to_s with jruby #1281

Closed
pinpox opened this issue May 4, 2015 · 10 comments
Closed

RuntimeError when calling to_s with jruby #1281

pinpox opened this issue May 4, 2015 · 10 comments
Milestone

Comments

@pinpox
Copy link

pinpox commented May 4, 2015

Hello
using Jruby with some html tags (Nokogiri xml elements) I get this error which crashes the program
the error doesnt always occur, so it is hard to provide a sample code, but it looks like

doc.css('meta').each do |t|
  puts t
  a << t.to_s
end

I think it might have to do with invalid encodings, but it's just a guess.
Is there a woraround for this?


RuntimeError: Input length = 1
  native_write_to at nokogiri/XmlNode.java:1217
         write_to at /home/binaryplease/.rvm/gems/jruby-1.7.19/gems/nokogiri-1.6.6.2-java/lib/nokogiri/xml/node.rb:686
        serialize at /home/binaryplease/.rvm/gems/jruby-1.7.19/gems/nokogiri-1.6.6.2-java/lib/nokogiri/xml/node.rb:618
        to_format at /home/binaryplease/.rvm/gems/jruby-1.7.19/gems/nokogiri-1.6.6.2-java/lib/nokogiri/xml/node.rb:774
          to_html at /home/binaryplease/.rvm/gems/jruby-1.7.19/gems/nokogiri-1.6.6.2-java/lib/nokogiri/xml/node.rb:630
             to_s at /home/binaryplease/.rvm/gems/jruby-1.7.19/gems/nokogiri-1.6.6.2-java/lib/nokogiri/xml/node.rb:501
    get_meta_tags at /home/binaryplease/committance/crawler2/crawler/crawler.rb:147
             each at /home/binaryplease/.rvm/gems/jruby-1.7.19/gems/nokogiri-1.6.6.2-java/lib/nokogiri/xml/node_set.rb:187
             upto at org/jruby/RubyInteger.java:133
             each at /home/binaryplease/.rvm/gems/jruby-1.7.19/gems/nokogiri-1.6.6.2-java/lib/nokogiri/xml/node_set.rb:186
    get_meta_tags at /home/binaryplease/committance/crawler2/crawler/crawler.rb:146
  fetch_page_tags at /home/binaryplease/committance/crawler2/crawler/crawler.rb:213
             each at org/jruby/RubyArray.java:1613
  fetch_page_tags at /home/binaryplease/committance/crawler2/crawler/crawler.rb:205
     get_contents at /home/binaryplease/committance/crawler2/crawler/crawler.rb:117
     process_link at /home/binaryplease/committance/crawler2/crawler/worker.rb:104
     process_link at /home/binaryplease/committance/crawler2/crawler/worker.rb:114
             each at org/jruby/RubyArray.java:1613
     process_link at /home/binaryplease/committance/crawler2/crawler/worker.rb:114
            start at /home/binaryplease/committance/crawler2/crawler/worker.rb:74
             each at org/jruby/RubyArray.java:1613
            start at /home/binaryplease/committance/crawler2/crawler/worker.rb:74
            start at /home/binaryplease/committance/crawler2/crawler/worker.rb:58
    process_batch at /home/binaryplease/committance/crawler2/crawler/crawler_client2.rb:120
             call at org/jruby/RubyProc.java:271
       initialize at /home/binaryplease/committance/crawler2/crawler/thread_pool.rb:14
             loop at org/jruby/RubyKernel.java:1507
       initialize at /home/binaryplease/committance/crawler2/crawler/thread_pool.rb:12
            catch at org/jruby/RubyKernel.java:1270
       initialize at /home/binaryplease/committance/crawler2/crawler/thread_pool.rb:11
@flavorjones
Copy link
Member

Hi,

Thanks for reporting this.

Unfortunately, without more information we cannot reproduce and thus won't be able to help. Can you please provide whatever you can to help us reproduce? The XML document in question would be a great help, as would any ruby code running on the script that might crash.

We would additionally need information about your system, which you can get by running nokogiri -v and pasting the output here.

@pinpox
Copy link
Author

pinpox commented May 4, 2015

Hello this is the output of nokogiri -v

binaryplease➜~(master✗)» rvm use jruby                                                                                                                                                                                               [23:47:14]
Using /home/binaryplease/.rvm/gems/jruby-1.7.19
binaryplease➜~(master✗)» nokogiri -v                                                                                                                                                                                                 [23:47:19]
# Nokogiri (1.6.6.2)
    ---
    warnings: []
    nokogiri: 1.6.6.2
    ruby:
      version: 1.9.3
      platform: java
      description: jruby 1.7.19 (1.9.3p551) 2015-02-21 32f5af0 on OpenJDK 64-Bit Server VM 1.8.0_45-b14 +jit [linux-amd64]
      engine: jruby
      jruby: 1.7.19
    xerces: Xerces-J 2.9.0
    nekohtml: NekoHTML 1.9.12

Ill apped any more information about the xml in question when I have it.
Thanks.

@jvshahid
Copy link
Member

Hi @binaryplease, is this issue reproducible on windows only ? I googled for this error and it looks like JRuby encoding issue that only on windows platforms.

@flavorjones
Copy link
Member

Closing, pending more information from the original poster.

@larcara
Copy link

larcara commented Mar 1, 2016

Hi have a similiar problem, that can be reproduced whit this snippet:

require 'nokogiri'
html_fragment=<<-eos
  <img width="16" height="16"  src="/icons/graycol.gif" border="0" alt="Inactive hide details for &quot;User&quot; ---19/05/2015 12:55:29---Provvediamo subito nell&#8217;integrare">
eos
doc = Nokogiri::HTML(html_fragment,nil,"ISO-8859-1")
doc.to_html

using

jruby 1.7.19 (1.9.3p551) 2015-01-29 20786bd on OpenJDK 64-Bit Server VM 1.7.0_95-b00 +jit [linux-amd64]

i obtain this error:

RuntimeError: Input length = 1
native_write_to at nokogiri/XmlNode.java:1217
write_to at /usr/local/rvm/gems/jruby-1.7.19/gems/nokogiri-1.6.6.2-java/lib/nokogiri/xml/node.rb:686
serialize at /usr/local/rvm/gems/jruby-1.7.19/gems/nokogiri-1.6.6.2-java/lib/nokogiri/xml/node.rb:618
serialize at /usr/local/rvm/gems/jruby-1.7.19/gems/nokogiri-1.6.6.2-java/lib/nokogiri/html/document.rb:144
to_format at /usr/local/rvm/gems/jruby-1.7.19/gems/nokogiri-1.6.6.2-java/lib/nokogiri/xml/node.rb:774
to_html at /usr/local/rvm/gems/jruby-1.7.19/gems/nokogiri-1.6.6.2-java/lib/nokogiri/xml/node.rb:630

@flavorjones
Copy link
Member

I've reproduced this issue, as reported on IRC by @jtarchie, using the docker image jruby:1.9:

root@8293aba7d4f6:/nokogiri# bundle exec rake
javac -extdirs "/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/ext:/usr/java/packages/lib/ext" -target 1.6 -source 1.6 -Xlint:unchecked  -cp "/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/resources.jar:/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/rt.jar:/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/sunrsasign.jar:/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/jsse.jar:/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/jce.jar:/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/charsets.jar:/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/jfr.jar:/usr/lib/jvm/java-8-openjdk-amd64/jre/classes:/opt/jruby/lib/jruby.jar:/opt/jruby/lib/jruby.jar:/nokogiri/lib/isorelax.jar:/nokogiri/lib/jing.jar:/nokogiri/lib/nekodtd.jar:/nokogiri/lib/nekohtml.jar:/nokogiri/lib/serializer.jar:/nokogiri/lib/xalan.jar:/nokogiri/lib/xercesImpl.jar:/nokogiri/lib/xml-apis.jar" -d tmp/java/nokogiri ext/java/nokogiri/EncodingHandler.java ext/java/nokogiri/HtmlDocument.java ext/java/nokogiri/HtmlElementDescription.java ext/java/nokogiri/HtmlEntityLookup.java ext/java/nokogiri/HtmlSaxParserContext.java ext/java/nokogiri/HtmlSaxPushParser.java ext/java/nokogiri/NokogiriService.java ext/java/nokogiri/XmlAttr.java ext/java/nokogiri/XmlAttributeDecl.java ext/java/nokogiri/XmlCdata.java ext/java/nokogiri/XmlComment.java ext/java/nokogiri/XmlDocument.java ext/java/nokogiri/XmlDocumentFragment.java ext/java/nokogiri/XmlDtd.java ext/java/nokogiri/XmlElement.java ext/java/nokogiri/XmlElementContent.java ext/java/nokogiri/XmlElementDecl.java ext/java/nokogiri/XmlEntityDecl.java ext/java/nokogiri/XmlEntityReference.java ext/java/nokogiri/XmlNamespace.java ext/java/nokogiri/XmlNode.java ext/java/nokogiri/XmlNodeSet.java ext/java/nokogiri/XmlProcessingInstruction.java ext/java/nokogiri/XmlReader.java ext/java/nokogiri/XmlRelaxng.java ext/java/nokogiri/XmlSaxParserContext.java ext/java/nokogiri/XmlSaxPushParser.java ext/java/nokogiri/XmlSchema.java ext/java/nokogiri/XmlSyntaxError.java ext/java/nokogiri/XmlText.java ext/java/nokogiri/XmlXpathContext.java ext/java/nokogiri/XsltStylesheet.java ext/java/nokogiri/internals/ClosedStreamException.java ext/java/nokogiri/internals/HtmlDomParserContext.java ext/java/nokogiri/internals/IgnoreSchemaErrorsErrorHandler.java ext/java/nokogiri/internals/NokogiriBlockingQueueInputStream.java ext/java/nokogiri/internals/NokogiriDocumentCache.java ext/java/nokogiri/internals/NokogiriDomParser.java ext/java/nokogiri/internals/NokogiriEncodingReaderWrapper.java ext/java/nokogiri/internals/NokogiriEntityResolver.java ext/java/nokogiri/internals/NokogiriErrorHandler.java ext/java/nokogiri/internals/NokogiriHandler.java ext/java/nokogiri/internals/NokogiriHelpers.java ext/java/nokogiri/internals/NokogiriNamespaceCache.java ext/java/nokogiri/internals/NokogiriNamespaceContext.java ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler.java ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler4NekoHtml.java ext/java/nokogiri/internals/NokogiriStrictErrorHandler.java ext/java/nokogiri/internals/NokogiriXPathFunction.java ext/java/nokogiri/internals/NokogiriXPathFunctionResolver.java ext/java/nokogiri/internals/NokogiriXPathVariableResolver.java ext/java/nokogiri/internals/NokogiriXsltErrorListener.java ext/java/nokogiri/internals/ParserContext.java ext/java/nokogiri/internals/ReaderNode.java ext/java/nokogiri/internals/SaveContextVisitor.java ext/java/nokogiri/internals/SchemaErrorHandler.java ext/java/nokogiri/internals/UncloseableInputStream.java ext/java/nokogiri/internals/XmlDeclHandler.java ext/java/nokogiri/internals/XmlDomParserContext.java ext/java/nokogiri/internals/XmlSaxParser.java ext/java/nokogiri/internals/XsltExtensionFunction.java ext/java/nokogiri/internals/c14n/AttrCompare.java ext/java/nokogiri/internals/c14n/C14nHelper.java ext/java/nokogiri/internals/c14n/CanonicalFilter.java ext/java/nokogiri/internals/c14n/CanonicalizationException.java ext/java/nokogiri/internals/c14n/Canonicalizer.java ext/java/nokogiri/internals/c14n/Canonicalizer11.java ext/java/nokogiri/internals/c14n/Canonicalizer11_OmitComments.java ext/java/nokogiri/internals/c14n/Canonicalizer11_WithComments.java ext/java/nokogiri/internals/c14n/Canonicalizer20010315.java ext/java/nokogiri/internals/c14n/Canonicalizer20010315Excl.java ext/java/nokogiri/internals/c14n/Canonicalizer20010315ExclOmitComments.java ext/java/nokogiri/internals/c14n/Canonicalizer20010315ExclWithComments.java ext/java/nokogiri/internals/c14n/Canonicalizer20010315OmitComments.java ext/java/nokogiri/internals/c14n/Canonicalizer20010315WithComments.java ext/java/nokogiri/internals/c14n/CanonicalizerBase.java ext/java/nokogiri/internals/c14n/CanonicalizerPhysical.java ext/java/nokogiri/internals/c14n/CanonicalizerSpi.java ext/java/nokogiri/internals/c14n/Constants.java ext/java/nokogiri/internals/c14n/ElementProxy.java ext/java/nokogiri/internals/c14n/HelperNodeList.java ext/java/nokogiri/internals/c14n/IgnoreAllErrorHandler.java ext/java/nokogiri/internals/c14n/InclusiveNamespaces.java ext/java/nokogiri/internals/c14n/InvalidCanonicalizerException.java ext/java/nokogiri/internals/c14n/NameSpaceSymbTable.java ext/java/nokogiri/internals/c14n/NodeFilter.java ext/java/nokogiri/internals/c14n/UtfHelpper.java ext/java/nokogiri/internals/c14n/XMLUtils.java
warning: [options] bootstrap class path not set in conjunction with -source 1.6
ext/java/nokogiri/internals/NokogiriHelpers.java:798: warning: [unchecked] unchecked call to getMethod(String,Class<?>...) as a member of the raw type Class
            nkf_method = nkfClass.getMethod("nkf", ThreadContext.class, IRubyObject.class, IRubyObject.class, IRubyObject.class);
                                           ^
ext/java/nokogiri/internals/NokogiriHandler.java:103: warning: [unchecked] unchecked conversion
        characterStack = new Stack();
                         ^
  required: Stack<StringBuffer>
  found:    Stack
ext/java/nokogiri/NokogiriService.java:83: warning: [unchecked] unchecked cast
        return (Map<String, RubyClass>) ruby.getModule("Nokogiri").getInternalVariable("cache");
                                                                                      ^
  required: Map<String,RubyClass>
  found:    Object
ext/java/nokogiri/XsltStylesheet.java:122: warning: [unchecked] unchecked conversion
        Set<String> keys = hash.keySet();
                                      ^
  required: Set<String>
  found:    Set
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
5 warnings
touch tmp/java/nokogiri/.build
jar cf tmp/java/nokogiri/nokogiri.jar -C tmp/java/nokogiri nokogiri/EncodingHandler.class -C tmp/java/nokogiri nokogiri/HtmlDocument.class -C tmp/java/nokogiri nokogiri/HtmlElementDescription.class -C tmp/java/nokogiri nokogiri/HtmlEntityLookup.class -C tmp/java/nokogiri nokogiri/HtmlSaxParserContext\$EncodingType.class -C tmp/java/nokogiri nokogiri/HtmlSaxParserContext.class -C tmp/java/nokogiri nokogiri/HtmlSaxPushParser\$1.class -C tmp/java/nokogiri nokogiri/HtmlSaxPushParser\$ParserTask.class -C tmp/java/nokogiri nokogiri/HtmlSaxPushParser.class -C tmp/java/nokogiri nokogiri/NokogiriService\$1.class -C tmp/java/nokogiri nokogiri/NokogiriService\$10.class -C tmp/java/nokogiri nokogiri/NokogiriService\$11.class -C tmp/java/nokogiri nokogiri/NokogiriService\$12.class -C tmp/java/nokogiri nokogiri/NokogiriService\$13.class -C tmp/java/nokogiri nokogiri/NokogiriService\$14.class -C tmp/java/nokogiri nokogiri/NokogiriService\$15.class -C tmp/java/nokogiri nokogiri/NokogiriService\$16.class -C tmp/java/nokogiri nokogiri/NokogiriService\$17.class -C tmp/java/nokogiri nokogiri/NokogiriService\$18.class -C tmp/java/nokogiri nokogiri/NokogiriService\$19.class -C tmp/java/nokogiri nokogiri/NokogiriService\$2.class -C tmp/java/nokogiri nokogiri/NokogiriService\$20.class -C tmp/java/nokogiri nokogiri/NokogiriService\$21.class -C tmp/java/nokogiri nokogiri/NokogiriService\$22.class -C tmp/java/nokogiri nokogiri/NokogiriService\$23.class -C tmp/java/nokogiri nokogiri/NokogiriService\$24.class -C tmp/java/nokogiri nokogiri/NokogiriService\$25.class -C tmp/java/nokogiri nokogiri/NokogiriService\$26.class -C tmp/java/nokogiri nokogiri/NokogiriService\$27.class -C tmp/java/nokogiri nokogiri/NokogiriService\$28.class -C tmp/java/nokogiri nokogiri/NokogiriService\$29.class -C tmp/java/nokogiri nokogiri/NokogiriService\$3.class -C tmp/java/nokogiri nokogiri/NokogiriService\$30.class -C tmp/java/nokogiri nokogiri/NokogiriService\$31.class -C tmp/java/nokogiri nokogiri/NokogiriService\$4.class -C tmp/java/nokogiri nokogiri/NokogiriService\$5.class -C tmp/java/nokogiri nokogiri/NokogiriService\$6.class -C tmp/java/nokogiri nokogiri/NokogiriService\$7.class -C tmp/java/nokogiri nokogiri/NokogiriService\$8.class -C tmp/java/nokogiri nokogiri/NokogiriService\$9.class -C tmp/java/nokogiri nokogiri/NokogiriService\$MonkeyPatchHTMLElements.class -C tmp/java/nokogiri nokogiri/NokogiriService.class -C tmp/java/nokogiri nokogiri/XmlAttr.class -C tmp/java/nokogiri nokogiri/XmlAttributeDecl.class -C tmp/java/nokogiri nokogiri/XmlCdata.class -C tmp/java/nokogiri nokogiri/XmlComment.class -C tmp/java/nokogiri nokogiri/XmlDocument.class -C tmp/java/nokogiri nokogiri/XmlDocumentFragment.class -C tmp/java/nokogiri nokogiri/XmlDtd.class -C tmp/java/nokogiri nokogiri/XmlElement.class -C tmp/java/nokogiri nokogiri/XmlElementContent\$1.class -C tmp/java/nokogiri nokogiri/XmlElementContent\$NodeIter.class -C tmp/java/nokogiri nokogiri/XmlElementContent\$Occur.class -C tmp/java/nokogiri nokogiri/XmlElementContent\$Type.class -C tmp/java/nokogiri nokogiri/XmlElementContent.class -C tmp/java/nokogiri nokogiri/XmlElementDecl.class -C tmp/java/nokogiri nokogiri/XmlEntityDecl.class -C tmp/java/nokogiri nokogiri/XmlEntityReference.class -C tmp/java/nokogiri nokogiri/XmlNamespace.class -C tmp/java/nokogiri nokogiri/XmlNode\$1.class -C tmp/java/nokogiri nokogiri/XmlNode\$AdoptScheme.class -C tmp/java/nokogiri nokogiri/XmlNode.class -C tmp/java/nokogiri nokogiri/XmlNodeSet.class -C tmp/java/nokogiri nokogiri/XmlProcessingInstruction.class -C tmp/java/nokogiri nokogiri/XmlReader\$DocumentHandler.class -C tmp/java/nokogiri nokogiri/XmlReader.class -C tmp/java/nokogiri nokogiri/XmlRelaxng.class -C tmp/java/nokogiri nokogiri/XmlSaxParserContext.class -C tmp/java/nokogiri nokogiri/XmlSaxPushParser\$1.class -C tmp/java/nokogiri nokogiri/XmlSaxPushParser\$ParserTask.class -C tmp/java/nokogiri nokogiri/XmlSaxPushParser.class -C tmp/java/nokogiri nokogiri/XmlSchema\$1.class -C tmp/java/nokogiri nokogiri/XmlSchema\$SchemaLSInput.class -C tmp/java/nokogiri nokogiri/XmlSchema\$SchemaResourceResolver.class -C tmp/java/nokogiri nokogiri/XmlSchema.class -C tmp/java/nokogiri nokogiri/XmlSyntaxError.class -C tmp/java/nokogiri nokogiri/XmlText.class -C tmp/java/nokogiri nokogiri/XmlXpathContext.class -C tmp/java/nokogiri nokogiri/XsltStylesheet\$1.class -C tmp/java/nokogiri nokogiri/XsltStylesheet.class -C tmp/java/nokogiri nokogiri/internals/ClosedStreamException.class -C tmp/java/nokogiri nokogiri/internals/HtmlDomParserContext\$1.class -C tmp/java/nokogiri nokogiri/internals/HtmlDomParserContext\$ElementValidityCheckFilter.class -C tmp/java/nokogiri nokogiri/internals/HtmlDomParserContext\$RemoveNSAttrsFilter.class -C tmp/java/nokogiri nokogiri/internals/HtmlDomParserContext.class -C tmp/java/nokogiri nokogiri/internals/IgnoreSchemaErrorsErrorHandler.class -C tmp/java/nokogiri nokogiri/internals/NokogiriBlockingQueueInputStream\$Task\$1.class -C tmp/java/nokogiri nokogiri/internals/NokogiriBlockingQueueInputStream\$Task.class -C tmp/java/nokogiri nokogiri/internals/NokogiriBlockingQueueInputStream.class -C tmp/java/nokogiri nokogiri/internals/NokogiriDocumentCache.class -C tmp/java/nokogiri nokogiri/internals/NokogiriDomParser\$1.class -C tmp/java/nokogiri nokogiri/internals/NokogiriDomParser\$NokogiriXInlcudeEntityResolver.class -C tmp/java/nokogiri nokogiri/internals/NokogiriDomParser.class -C tmp/java/nokogiri nokogiri/internals/NokogiriEncodingReaderWrapper.class -C tmp/java/nokogiri nokogiri/internals/NokogiriEntityResolver.class -C tmp/java/nokogiri nokogiri/internals/NokogiriErrorHandler.class -C tmp/java/nokogiri nokogiri/internals/NokogiriHandler.class -C tmp/java/nokogiri nokogiri/internals/NokogiriHelpers.class -C tmp/java/nokogiri nokogiri/internals/NokogiriNamespaceCache\$CacheEntry.class -C tmp/java/nokogiri nokogiri/internals/NokogiriNamespaceCache.class -C tmp/java/nokogiri nokogiri/internals/NokogiriNamespaceContext.class -C tmp/java/nokogiri nokogiri/internals/NokogiriNonStrictErrorHandler.class -C tmp/java/nokogiri nokogiri/internals/NokogiriNonStrictErrorHandler4NekoHtml.class -C tmp/java/nokogiri nokogiri/internals/NokogiriStrictErrorHandler.class -C tmp/java/nokogiri nokogiri/internals/NokogiriXPathFunction.class -C tmp/java/nokogiri nokogiri/internals/NokogiriXPathFunctionResolver.class -C tmp/java/nokogiri nokogiri/internals/NokogiriXPathVariableResolver.class -C tmp/java/nokogiri nokogiri/internals/NokogiriXsltErrorListener\$ErrorType.class -C tmp/java/nokogiri nokogiri/internals/NokogiriXsltErrorListener.class -C tmp/java/nokogiri nokogiri/internals/ParserContext\$NokogiriXInlcudeEntityResolver.class -C tmp/java/nokogiri nokogiri/internals/ParserContext\$Options.class -C tmp/java/nokogiri nokogiri/internals/ParserContext.class -C tmp/java/nokogiri nokogiri/internals/ReaderNode\$ClosingNode.class -C tmp/java/nokogiri nokogiri/internals/ReaderNode\$ElementNode.class -C tmp/java/nokogiri nokogiri/internals/ReaderNode\$EmptyNode.class -C tmp/java/nokogiri nokogiri/internals/ReaderNode\$ExceptionNode.class -C tmp/java/nokogiri nokogiri/internals/ReaderNode\$ReaderAttributeList.class -C tmp/java/nokogiri nokogiri/internals/ReaderNode\$ReaderNodeType.class -C tmp/java/nokogiri nokogiri/internals/ReaderNode\$TextNode.class -C tmp/java/nokogiri nokogiri/internals/ReaderNode.class -C tmp/java/nokogiri nokogiri/internals/SaveContextVisitor\$1.class -C tmp/java/nokogiri nokogiri/internals/SaveContextVisitor.class -C tmp/java/nokogiri nokogiri/internals/SchemaErrorHandler.class -C tmp/java/nokogiri nokogiri/internals/UncloseableInputStream.class -C tmp/java/nokogiri nokogiri/internals/XmlDeclHandler.class -C tmp/java/nokogiri nokogiri/internals/XmlDomParserContext.class -C tmp/java/nokogiri nokogiri/internals/XmlSaxParser.class -C tmp/java/nokogiri nokogiri/internals/XsltExtensionFunction.class -C tmp/java/nokogiri nokogiri/internals/c14n/AttrCompare.class -C tmp/java/nokogiri nokogiri/internals/c14n/C14nHelper.class -C tmp/java/nokogiri nokogiri/internals/c14n/CanonicalFilter.class -C tmp/java/nokogiri nokogiri/internals/c14n/CanonicalizationException.class -C tmp/java/nokogiri nokogiri/internals/c14n/Canonicalizer.class -C tmp/java/nokogiri nokogiri/internals/c14n/Canonicalizer11\$1.class -C tmp/java/nokogiri nokogiri/internals/c14n/Canonicalizer11\$XmlAttrStack\$XmlsStackElement.class -C tmp/java/nokogiri nokogiri/internals/c14n/Canonicalizer11\$XmlAttrStack.class -C tmp/java/nokogiri nokogiri/internals/c14n/Canonicalizer11.class -C tmp/java/nokogiri nokogiri/internals/c14n/Canonicalizer11_OmitComments.class -C tmp/java/nokogiri nokogiri/internals/c14n/Canonicalizer11_WithComments.class -C tmp/java/nokogiri nokogiri/internals/c14n/Canonicalizer20010315\$1.class -C tmp/java/nokogiri nokogiri/internals/c14n/Canonicalizer20010315\$XmlAttrStack\$XmlsStackElement.class -C tmp/java/nokogiri nokogiri/internals/c14n/Canonicalizer20010315\$XmlAttrStack.class -C tmp/java/nokogiri nokogiri/internals/c14n/Canonicalizer20010315.class -C tmp/java/nokogiri nokogiri/internals/c14n/Canonicalizer20010315Excl.class -C tmp/java/nokogiri nokogiri/internals/c14n/Canonicalizer20010315ExclOmitComments.class -C tmp/java/nokogiri nokogiri/internals/c14n/Canonicalizer20010315ExclWithComments.class -C tmp/java/nokogiri nokogiri/internals/c14n/Canonicalizer20010315OmitComments.class -C tmp/java/nokogiri nokogiri/internals/c14n/Canonicalizer20010315WithComments.class -C tmp/java/nokogiri nokogiri/internals/c14n/CanonicalizerBase.class -C tmp/java/nokogiri nokogiri/internals/c14n/CanonicalizerPhysical.class -C tmp/java/nokogiri nokogiri/internals/c14n/CanonicalizerSpi.class -C tmp/java/nokogiri nokogiri/internals/c14n/Constants.class -C tmp/java/nokogiri nokogiri/internals/c14n/ElementProxy.class -C tmp/java/nokogiri nokogiri/internals/c14n/HelperNodeList.class -C tmp/java/nokogiri nokogiri/internals/c14n/IgnoreAllErrorHandler.class -C tmp/java/nokogiri nokogiri/internals/c14n/InclusiveNamespaces.class -C tmp/java/nokogiri nokogiri/internals/c14n/InvalidCanonicalizerException.class -C tmp/java/nokogiri nokogiri/internals/c14n/NameSpaceSymbEntry.class -C tmp/java/nokogiri nokogiri/internals/c14n/NameSpaceSymbTable.class -C tmp/java/nokogiri nokogiri/internals/c14n/NodeFilter.class -C tmp/java/nokogiri nokogiri/internals/c14n/SymbMap.class -C tmp/java/nokogiri nokogiri/internals/c14n/UtfHelpper.class -C tmp/java/nokogiri nokogiri/internals/c14n/XMLUtils.class
install -c tmp/java/nokogiri/nokogiri.jar lib/nokogiri/nokogiri.jar
/opt/jruby/bin/jruby -w -Ilib:bin:test:. -e 'require "rubygems"; require "minitest/autorun"; require "test/test_memory_leak.rb"; require "test/test_encoding_handler.rb"; require "test/test_soap4r_sax.rb"; require "test/test_xslt_transforms.rb"; require "test/test_convert_xpath.rb"; require "test/test_css_cache.rb"; require "test/test_nokogiri.rb"; require "test/css/test_tokenizer.rb"; require "test/css/test_parser.rb"; require "test/css/test_nthiness.rb"; require "test/css/test_xpath_visitor.rb"; require "test/xslt/test_exception_handling.rb"; require "test/xslt/test_custom_functions.rb"; require "test/namespaces/test_additional_namespaces_in_builder_doc.rb"; require "test/namespaces/test_namespaces_aliased_default.rb"; require "test/namespaces/test_namespaces_in_cloned_doc.rb"; require "test/namespaces/test_namespaces_in_parsed_doc.rb"; require "test/namespaces/test_namespaces_in_created_doc.rb"; require "test/namespaces/test_namespaces_in_builder_doc.rb"; require "test/namespaces/test_namespaces_preservation.rb"; require "test/html/test_builder.rb"; require "test/html/test_node.rb"; require "test/html/test_document_encoding.rb"; require "test/html/test_node_encoding.rb"; require "test/html/test_named_characters.rb"; require "test/html/test_element_description.rb"; require "test/html/test_document.rb"; require "test/html/test_document_fragment.rb"; require "test/html/sax/test_parser_context.rb"; require "test/html/sax/test_parser.rb"; require "test/html/sax/test_push_parser.rb"; require "test/decorators/test_slop.rb"; require "test/xml/test_builder.rb"; require "test/xml/test_c14n.rb"; require "test/xml/test_node.rb"; require "test/xml/test_attr.rb"; require "test/xml/test_node_inheritance.rb"; require "test/xml/test_namespace.rb"; require "test/xml/test_dtd_encoding.rb"; require "test/xml/test_reader_encoding.rb"; require "test/xml/test_processing_instruction.rb"; require "test/xml/test_document_encoding.rb"; require "test/xml/test_element_content.rb"; require "test/xml/test_node_encoding.rb"; require "test/xml/test_xinclude.rb"; require "test/xml/test_element_decl.rb"; require "test/xml/test_cdata.rb"; require "test/xml/test_text.rb"; require "test/xml/test_parse_options.rb"; require "test/xml/test_node_reparenting.rb"; require "test/xml/test_reader.rb"; require "test/xml/test_comment.rb"; require "test/xml/test_schema.rb"; require "test/xml/test_document.rb"; require "test/xml/test_entity_reference.rb"; require "test/xml/test_dtd.rb"; require "test/xml/test_relax_ng.rb"; require "test/xml/test_entity_decl.rb"; require "test/xml/test_xpath.rb"; require "test/xml/test_node_attributes.rb"; require "test/xml/test_node_set.rb"; require "test/xml/test_syntax_error.rb"; require "test/xml/test_attribute_decl.rb"; require "test/xml/test_document_fragment.rb"; require "test/xml/test_unparented_node.rb"; require "test/xml/node/test_subclass.rb"; require "test/xml/node/test_save_options.rb"; require "test/xml/sax/test_parser_context.rb"; require "test/xml/sax/test_parser.rb"; require "test/xml/sax/test_push_parser.rb"' -- 
/nokogiri/test/helper.rb:15: version info: {"warnings"=>[], "nokogiri"=>"1.6.8", "ruby"=>{"version"=>"2.3.1", "platform"=>"java", "description"=>"jruby 9.1.6.0 (2.3.1) 2016-11-09 0150a76 OpenJDK 64-Bit Server VM 25.111-b14 on 1.8.0_111-8u111-b14-2~bpo8+1-b14 [linux-x86_64]", "engine"=>"jruby", "jruby"=>"9.1.6.0"}, "xerces"=>"Xerces-J 2.11.0", "nekohtml"=>"NekoHTML 1.9.21"}
Run options: --seed 49971

# Running:

..........................................................................................................................................................................................................................................................................................................................................................................E...............................S...................S.SSS.......................................................................................................................................................................................................................................................................................................S.............E...............E..........E..EE........................E...............................................S.SSS...................................................................................................................................................................................................................................S.......................................................................................................F...................................S..........................................................................................................................................................................

Fabulous run in 29.106729s, 47.2399 runs/s, 132.3749 assertions/s.

  1) Error:
TestNokogiri#test_nokogiri_method_with_html:
RuntimeError: Input length = 1
    nokogiri/XmlNode.java:1274:in `native_write_to'
    /nokogiri/lib/nokogiri/xml/node.rb:698:in `write_to'
    /nokogiri/lib/nokogiri/xml/node.rb:630:in `serialize'
    /nokogiri/lib/nokogiri/html/document.rb:144:in `serialize'
    /nokogiri/test/test_nokogiri.rb:59:in `test_nokogiri_method_with_html'


  2) Error:
Nokogiri::HTML::TestDocument#test_serialize:
RuntimeError: Input length = 1
    nokogiri/XmlNode.java:1274:in `native_write_to'
    /nokogiri/lib/nokogiri/xml/node.rb:698:in `write_to'
    /nokogiri/lib/nokogiri/xml/node.rb:630:in `serialize'
    /nokogiri/lib/nokogiri/html/document.rb:144:in `serialize'
    /nokogiri/test/html/test_document.rb:620:in `test_serialize'


  3) Error:
Nokogiri::HTML::TestDocument#test_dup_document:
RuntimeError: Input length = 1
    nokogiri/XmlNode.java:1274:in `native_write_to'
    /nokogiri/lib/nokogiri/xml/node.rb:698:in `write_to'
    /nokogiri/lib/nokogiri/xml/node.rb:630:in `serialize'
    /nokogiri/lib/nokogiri/html/document.rb:144:in `serialize'
    /nokogiri/lib/nokogiri/xml/node.rb:786:in `to_format'
    /nokogiri/lib/nokogiri/xml/node.rb:642:in `to_html'
    /nokogiri/lib/nokogiri/xml/node.rb:512:in `to_s'
    /nokogiri/test/html/test_document.rb:519:in `test_dup_document'


  4) Error:
Nokogiri::HTML::TestDocument#test_document_parse_method:
RuntimeError: Input length = 1
    nokogiri/XmlNode.java:1274:in `native_write_to'
    /nokogiri/lib/nokogiri/xml/node.rb:698:in `write_to'
    /nokogiri/lib/nokogiri/xml/node.rb:630:in `serialize'
    /nokogiri/lib/nokogiri/html/document.rb:144:in `serialize'
    /nokogiri/lib/nokogiri/xml/node.rb:786:in `to_format'
    /nokogiri/lib/nokogiri/xml/node.rb:642:in `to_html'
    /nokogiri/lib/nokogiri/xml/node.rb:512:in `to_s'
    /nokogiri/test/html/test_document.rb:90:in `test_document_parse_method'


  5) Error:
Nokogiri::HTML::TestDocument#test_round_trip:
RuntimeError: Input length = 1
    nokogiri/XmlNode.java:1274:in `native_write_to'
    /nokogiri/lib/nokogiri/xml/node.rb:698:in `write_to'
    /nokogiri/lib/nokogiri/xml/node.rb:630:in `serialize'
    /nokogiri/lib/nokogiri/xml/node.rb:786:in `to_format'
    /nokogiri/lib/nokogiri/xml/node.rb:642:in `to_html'
    /nokogiri/lib/nokogiri/xml/node.rb:517:in `block in inner_html'
    /nokogiri/lib/nokogiri/xml/node_set.rb:187:in `block in each'
    org/jruby/RubyInteger.java:134:in `upto'
    /nokogiri/lib/nokogiri/xml/node_set.rb:186:in `each'
    org/jruby/RubyEnumerable.java:829:in `map'
    /nokogiri/lib/nokogiri/xml/node.rb:517:in `inner_html'
    /nokogiri/test/html/test_document.rb:552:in `test_round_trip'


  6) Error:
Nokogiri::HTML::TestDocument#test_subclass_parse:
RuntimeError: Input length = 1
    nokogiri/XmlNode.java:1274:in `native_write_to'
    /nokogiri/lib/nokogiri/xml/node.rb:698:in `write_to'
    /nokogiri/lib/nokogiri/xml/node.rb:630:in `serialize'
    /nokogiri/lib/nokogiri/html/document.rb:144:in `serialize'
    /nokogiri/lib/nokogiri/xml/node.rb:786:in `to_format'
    /nokogiri/lib/nokogiri/xml/node.rb:642:in `to_html'
    /nokogiri/lib/nokogiri/xml/node.rb:512:in `to_s'
    /nokogiri/test/html/test_document.rb:84:in `test_subclass_parse'


  7) Error:
Nokogiri::HTML::TestDocument#test_to_xhtml:
RuntimeError: Input length = 1
    nokogiri/XmlNode.java:1274:in `native_write_to'
    /nokogiri/lib/nokogiri/xml/node.rb:698:in `write_to'
    /nokogiri/lib/nokogiri/xml/node.rb:630:in `serialize'
    /nokogiri/lib/nokogiri/html/document.rb:144:in `serialize'
    /nokogiri/lib/nokogiri/xml/node.rb:786:in `to_format'
    /nokogiri/lib/nokogiri/xml/node.rb:663:in `to_xhtml'
    /nokogiri/test/html/test_document.rb:368:in `test_to_xhtml'


  8) Failure:
Nokogiri::HTML::SAX::TestParser#test_parse_force_encoding [/nokogiri/test/html/sax/test_parser.rb:67]:
--- expected
+++ actual
@@ -1 +1 @@
-"\u0418\u043D\u0444\u043E\u0440\u043C\u0430\u0446\u0438\u044F"
+"??????????"


1375 runs, 3853 assertions, 1 failures, 7 errors, 12 skips

You have skipped tests. Run with --verbose for details.
rake aborted!
Command failed with status (1): [/opt/jruby/bin/jruby -w -Ilib:bin:test:. -...]
/usr/local/bundle/gems/hoe-3.15.3/lib/hoe/test.rb:83:in `block in define_test_tasks'
/opt/jruby/bin/bundle:22:in `<main>'
Tasks: TOP => default => test
(See full trace by running task with --trace)

@jvshahid
Copy link
Member

jvshahid commented Dec 6, 2016

I looked at this issue briefly. Looks like the RuntimeException root cause is UnmappableCharacterException being thrown on this line. Looks like for some reason we're getting back invalid characters. note I verified this behavior on both jdk 7 and 8. The following patch ignores the invalid characters, but I'm still not sure why we're suddenly getting back invalid characters. Finally, the failure in SAX::TestParser is caused by xerces passing the string ?????... to the characters method of the parser handler. This could be caused by the same issue, i.e. we're passing invalid characters to xerces and xerces is replacing the invalid characters with question marks ?.

From 2604f658412c2573086bc7865c91a2b1109b0b9c Mon Sep 17 00:00:00 2001
From: John Shahid <[email protected]>
Date: Tue, 6 Dec 2016 08:47:33 -0500
Subject: [PATCH] fix the exceptions

---
 ext/java/nokogiri/internals/NokogiriHelpers.java | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/ext/java/nokogiri/internals/NokogiriHelpers.java b/ext/java/nokogiri/internals/NokogiriHelpers.java
index 32cab693..1dbd2eb5 100644
--- a/ext/java/nokogiri/internals/NokogiriHelpers.java
+++ b/ext/java/nokogiri/internals/NokogiriHelpers.java
@@ -38,6 +38,7 @@ import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.nio.ByteBuffer;
 import java.nio.CharBuffer;
+import java.nio.charset.CodingErrorAction;
 import java.nio.charset.CharacterCodingException;
 import java.nio.charset.Charset;
 import java.nio.charset.CharsetEncoder;
@@ -743,6 +744,7 @@ public class NokogiriHelpers {
     public static byte[] convertEncoding(Charset output_charset, String input_string) throws CharacterCodingException {
         CharsetEncoder encoder = output_charset.newEncoder();
         CharBuffer charBuffer = CharBuffer.wrap(input_string);
+        encoder.onUnmappableCharacter(CodingErrorAction.IGNORE);
         ByteBuffer byteBuffer = encoder.encode(charBuffer);
         byte[] buffer = new byte[byteBuffer.remaining()];
         byteBuffer.get(buffer);
-- 
2.11.0

@jvshahid
Copy link
Member

jvshahid commented Dec 6, 2016

I'd like to run those tests outside the docker image, but unfortunately i'm having trouble getting jruby 9.1 to install on the host machine. i'll report back once i get it installed and run the test suite

@flavorjones
Copy link
Member

@kares has submitted a fix for this in #1597

@flavorjones flavorjones added this to the 1.7.1 milestone Feb 10, 2017
@flavorjones
Copy link
Member

Fixed in master, will be in v1.7.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants