asciidoctor / asciidoctorj

:coffee: Java bindings for Asciidoctor. Asciidoctor on the JVM!
http://asciidoctor.org
Apache License 2.0
628 stars 172 forks source link

Switched from java 11 to 17 and now get `initialize': wrong number of arguments (given 1, expected 0) #1285

Open zenbones opened 1 month ago

zenbones commented 1 month ago

The import is...

      <dependency>
        <groupId>org.asciidoctor</groupId>
        <artifactId>asciidoctorj</artifactId>
        <version>3.0.0</version>
      </dependency>

...but I see the same 2.5.7.

The code is...

    try (Asciidoctor asciidoctor = Asciidoctor.Factory.create()) {

      return asciidoctor.convert(<string to convert>, Options.builder().build());
    }

...and I now get...

Caused by: org.smallmind.web.json.scaffold.fault.NativeObjectException: Exception in thread org.jruby.exceptions.ArgumentError: (ArgumentError) asciidoctor: FAILED: <stdin>: Failed to load AsciiDoc document - `initialize': wrong number of arguments (given 1, expected 0)
   at RUBY.load(uri:classloader:/gems/asciidoctor-2.0.23/lib/asciidoctor/load.rb:104)
   at RUBY.convert(uri:classloader:/gems/asciidoctor-2.0.23/lib/asciidoctor/convert.rb:78)
Caused by: org.jruby.exceptions.ArgumentError: (ArgumentError) `initialize': wrong number of arguments (given 1, expected 0)
   at org.jruby.RubyClass.new(org/jruby/RubyClass.java:922)
   at RUBY.initialize(uri:classloader:/gems/asciidoctor-2.0.23/lib/asciidoctor/attribute_list.rb:54)
   at org.jruby.RubyClass.new(org/jruby/RubyClass.java:935)
   at RUBY.parse_attributes(uri:classloader:/gems/asciidoctor-2.0.23/lib/asciidoctor/substitutors.rb:1337)
   at uri_3a_classloader_3a_.gems.asciidoctor_minus_2_dot_0_dot_23.lib.asciidoctor.parser.parse_block_metadata_line(uri:classloader:/gems/asciidoctor-2.0.23/lib/asciidoctor/parser.rb:2059)
   at uri_3a_classloader_3a_.gems.asciidoctor_minus_2_dot_0_dot_23.lib.asciidoctor.parser.parse_block_metadata_lines(uri:classloader:/gems/asciidoctor-2.0.23/lib/asciidoctor/parser.rb:2015)
   at uri_3a_classloader_3a_.gems.asciidoctor_minus_2_dot_0_dot_23.lib.asciidoctor.parser.next_section(uri:classloader:/gems/asciidoctor-2.0.23/lib/asciidoctor/parser.rb:373)
   at uri_3a_classloader_3a_.gems.asciidoctor_minus_2_dot_0_dot_23.lib.asciidoctor.parser.next_section(uri:classloader:/gems/asciidoctor-2.0.23/lib/asciidoctor/parser.rb:388)
   at RUBY.next_section(uri:classloader:/gems/asciidoctor-2.0.23/lib/asciidoctor/parser.rb:388)
   at RUBY.parse(uri:classloader:/gems/asciidoctor-2.0.23/lib/asciidoctor/parser.rb:103)
   at RUBY.parse(uri:classloader:/gems/asciidoctor-2.0.23/lib/asciidoctor/document.rb:538)
   at RUBY.load(uri:classloader:/gems/asciidoctor-2.0.23/lib/asciidoctor/load.rb:84)
   ... 1 more
zenbones commented 1 month ago

I get this error in ubuntu 22.04, openjdk 17, but not in windows with graalvm 17, if that helps...

abelsromero commented 1 month ago

...but I see the same 2.5.7.

Can you clarify this comment? mvn dependency:tree should show if there's some other version in runtime...even though I thought Maven would pull the latest is set in the pom.

btw, AsciidoctorJ 3.0.0 uses asciidoctor v2.0.23, at least we know that version is in the classpath

zenbones commented 1 month ago

What I mean is that I get that error under openjdk17 on ubuntu 22.04 with only 2.5.7 on the classpath, or only 3.0.0 on the classpath, but not both at the same time. I can guarantee the classpath because all of our jars are pulled and collected into a lib directory that serves as the classpath for tanukisoft scripts that are hosting the jvm, and all versions are fully sepcified in maven poms, and I have checked both the jars available to my local IDE (intelij), and the jars packed into the tanukisoft distribution, and they are both clean, either 2.5.7 or 3.0.0.

Here's the relevant bit from the lib directory...

apiguardian-api-1.1.2.jar artifact-maven-6.0.0-SNAPSHOT.jar asciidoctorj-3.0.0.jar asciidoctorj-api-3.0.0.jar asm-9.7.jar asm-analysis-9.7.jar

..and the only asciidoctor jars are both 3.0.0. I would obviously prefer to resolve this issue with 3.0.0.

What I'm really asking is what the mechanism is that would cause that error. My ability to debug easily ends with...

org.jruby.RubyClass.new(org/jruby/RubyClass.java:922

...and the code there is a dynamic reference into some ruby code, I think... I have no clue how to go further. Is there a file in the asciidoctor jars I can double check? A line of code that should have some signature? Or some piece of java being loaded as a service?

zenbones commented 1 month ago

I also checked the maven repository on the tanukisoft-based install where I get the error, and it's empty except for a few of our jars containing classpath available text templates. Nothing else in it, so the only asciidocj code on the machine is the 3.0.0 jars listed above. Just as proof maven isn't downloading other versions somehow and confusing the classpath.

rpanzer-aviatrix commented 1 month ago

It would be great if you could provide a reproducer. It might make sense checking what JRuby jars are used.

zenbones commented 1 month ago

I'd like to hand you a reproducer, but I develop on windows, where I can't get a reproduction. Everything works fine. In ubuntu 24.04 I can reproduce in 2.5.7 0r 3.0.0. If I change the asciidoctorj version in my maven pom to 2.5.2 then the problem goes away in linux as well. With 3.0.0 it pulls jruby 9.4.8.0, which is not surprising as that's the listed dependency. With 2.5.2 it's jruby 9.2.17.0.

I'll try to put together a reproducer in linux and see. The document we feed to asciidoctorj is dynamically constructed, so i's a bit difficult, but I'll see what I can do, maybe capture it and create something small and runnable.