Skip to content

Commit

Permalink
Change return type to RubyArray
Browse files Browse the repository at this point in the history
The existing signature conflicts with one added to JRuby 9.2.9.
Specifically, the new signature in JRuby returns RubyArray, which
causes a compilation error on this line in Nokogiri because it
attempts to use a more general return type.

We would prefer to keep the specific return type in JRuby.

* If we patch JRuby, then 9.2.9 will never be able to compile any
  version of Nokogiri.
* If we patch Nokogiri, all versions of JRuby can compile current
  and future Nokogiri. Versions prior to 9.2.9 will be able to
  compile all existing releases of Nokogiri.

I do not believe the change in 9.2.9 breaks anything at runtime,
since the JVM does not care about this particular return type
mismatch unless someone actually returns a non-RubyArray object.

Fixes #1968
  • Loading branch information
headius authored and flavorjones committed Mar 1, 2020
1 parent ae054f7 commit 9b5deef
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion ext/java/nokogiri/XmlNodeSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import java.util.Arrays;

import org.jruby.Ruby;
import org.jruby.RubyArray;
import org.jruby.RubyClass;
import org.jruby.RubyFixnum;
import org.jruby.RubyObject;
Expand Down Expand Up @@ -391,7 +392,7 @@ public IRubyObject subseq(ThreadContext context, int start, int length) {
}

@JRubyMethod(name = {"to_a", "to_ary"})
public IRubyObject to_a(ThreadContext context) {
public RubyArray to_a(ThreadContext context) {
return context.runtime.newArrayNoCopy(nodes);
}

Expand Down

0 comments on commit 9b5deef

Please sign in to comment.