Skip to content

Commit

Permalink
Merge pull request #1723 from kares/fix-jruby-compat
Browse files Browse the repository at this point in the history
[fix] avoid potential (legacy) issues booting on newer JRubies
  • Loading branch information
flavorjones committed Feb 25, 2018
2 parents d178157 + 71bd4be commit f40cba7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 25 deletions.
8 changes: 0 additions & 8 deletions Rakefile
Expand Up @@ -292,14 +292,6 @@ task :java_debug do
ENV['JAVA_OPTS'] = '-Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=y' if ENV['JAVA_DEBUG']
end

if java?
task :test_19 => :test
task :test_20 do
ENV['JRUBY_OPTS'] = "--2.0"
Rake::Task["test"].invoke
end
end

Rake::Task[:test].prerequisites << :compile
Rake::Task[:test].prerequisites << :java_debug
Rake::Task[:test].prerequisites << :check_extra_deps unless java?
Expand Down
26 changes: 9 additions & 17 deletions ext/java/nokogiri/XmlSyntaxError.java
Expand Up @@ -34,10 +34,10 @@

import static nokogiri.internals.NokogiriHelpers.stringOrNil;

import org.jruby.CompatVersion;
import org.jruby.Ruby;
import org.jruby.RubyClass;
import org.jruby.RubyException;
import org.jruby.RubyString;
import org.jruby.anno.JRubyClass;
import org.jruby.anno.JRubyMethod;
import org.jruby.runtime.ThreadContext;
Expand Down Expand Up @@ -120,26 +120,18 @@ public void setException(Ruby runtime, SAXParseException exception, int level) {
setInstanceVariable("@file", stringOrNil(runtime, exception.getSystemId()));
}

//@Override
//"to_s" method was branched in 1.8 and 1.9 since JRuby 1.6.6
// to support older version of JRuby, the annotation is commented out
// NOTE: special care - due JRuby 1.7.x

@Override
@JRubyMethod(name = "to_s", compat = CompatVersion.RUBY1_8)
public IRubyObject to_s(ThreadContext context) {
IRubyObject msg = msg(context.runtime);
return msg != null ? msg : super.to_s(context);
}
public IRubyObject to_s(ThreadContext context) { return to_s19(context); }

//@Override
//"to_s" method was branched in 1.8 and 1.9 since JRuby 1.6.6
// to support older version of JRuby, the annotation is commented out
@JRubyMethod(name = "to_s", compat = CompatVersion.RUBY1_9)
public IRubyObject to_s19(ThreadContext context) {
IRubyObject msg = msg(context.runtime);
return msg != null ? msg : super.to_s19(context);
@JRubyMethod(name = "to_s")
public RubyString to_s19(ThreadContext context) {
RubyString msg = msg(context.runtime);
return msg != null ? msg : super.to_s(context).asString();
}

private IRubyObject msg(final Ruby runtime) {
private RubyString msg(final Ruby runtime) {
if (exception != null && exception.getMessage() != null) {
if (messageSet) return null;
return runtime.newString( exception.getMessage() );
Expand Down

0 comments on commit f40cba7

Please sign in to comment.