gettalong / hexapdf

Versatile PDF creation and manipulation for Ruby
https://hexapdf.gettalong.org
Other
1.22k stars 69 forks source link

JRuby failure #190

Closed djberg96 closed 2 years ago

djberg96 commented 2 years ago

jruby 9.3.4.0 (2.6.8) 2022-03-23 eff48c1ebf OpenJDK 64-Bit Server VM 18.0.2+0 on 18.0.2+0 +jit [arm64-darwin] hexapdf 0.24.1

I was just tinkering with JRuby and hexapdf, but I noticed even a basic script like this fails:

require 'hexapdf'
pdf = HexaPDF::Document.open(some_pdf_file)

Output:

NoMethodError: undefined method `last' for 6:Integer
                each at /Users/daniel.berger/.rbenv/versions/jruby-9.3.4.0/lib/ruby/gems/shared/gems/hexapdf-0.24.1/lib/hexapdf/pdf_array.rb:183
          each_index at org/jruby/RubyArray.java:1926
                each at /Users/daniel.berger/.rbenv/versions/jruby-9.3.4.0/lib/ruby/gems/shared/gems/hexapdf-0.24.1/lib/hexapdf/pdf_array.rb:183
          each_slice at org/jruby/RubyEnumerable.java:1174
                each at org/jruby/RubyEnumerator.java:392
                 sum at org/jruby/RubyEnumerable.java:876
  parse_xref_section at /Users/daniel.berger/.rbenv/versions/jruby-9.3.4.0/lib/ruby/gems/shared/gems/hexapdf-0.24.1/lib/hexapdf/type/xref_stream.rb:139
        xref_section at /Users/daniel.berger/.rbenv/versions/jruby-9.3.4.0/lib/ruby/gems/shared/gems/hexapdf-0.24.1/lib/hexapdf/type/xref_stream.rb:88
       load_revision at /Users/daniel.berger/.rbenv/versions/jruby-9.3.4.0/lib/ruby/gems/shared/gems/hexapdf-0.24.1/lib/hexapdf/parser.rb:228
             from_io at /Users/daniel.berger/.rbenv/versions/jruby-9.3.4.0/lib/ruby/gems/shared/gems/hexapdf-0.24.1/lib/hexapdf/revisions.rb:86
          initialize at /Users/daniel.berger/.rbenv/versions/jruby-9.3.4.0/lib/ruby/gems/shared/gems/hexapdf-0.24.1/lib/hexapdf/document.rb:168
                 new at org/jruby/RubyClass.java:888
                open at /Users/daniel.berger/.rbenv/versions/jruby-9.3.4.0/lib/ruby/gems/shared/gems/hexapdf-0.24.1/lib/hexapdf/document.rb:137

It works fine with MRI. Any ideas?

gettalong commented 2 years ago

The test suite of HexaPDF never ran successfully under JRuby. I just tried it out with the latest version 9.3.7.0 and it still has 72 errors, many of them begin exactly the one you encountered (undefined methodlast' for <???>:Integer`).

It often comes down to this line (as with your case) which JRuby can't handle:

needed_bytes = (w0 + w1 + w2) * index.each_slice(2).sum(&:last)

I don't really know why it can't handle that line. And since I personally don't use JRuby and there was no need from somebody else, I didn't investigate. However, since the test suite runs fine on MRI and on TruffleRuby, my guess is that JRuby is not 100% compatible with MRI.

djberg96 commented 2 years ago

@gettalong Thanks, I've reported it at https://github.com/jruby/jruby/issues/7326.

gettalong commented 2 years ago

I can re-open this issue if there is anything to do on HexaPDF's side.

djberg96 commented 2 years ago

Already fixed in JRuby. I'll try again when they push out a new release. :)

gettalong commented 2 years ago

@djberg96 Great, thank you!