Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fix compare_to for to_java'ed Ruby objects #1626

Merged
merged 1 commit into from

2 participants

Daniel Marcotte Thomas E Enebo
Daniel Marcotte

Flip incorrect nil check which was resulting in #compare_to always returning 0 for many to_java'ed Ruby objects (anything not internally represented by a class which overrides RubyBasicObject#compareTo)

Fixes #1520

Daniel Marcotte dmarcotte Fix compare_to for to_java'ed Ruby objects
Flip incorrect nil check which was resulting in #compare_to always
returning 0 for many to_java'ed Ruby objects (anything not internally
represented by a class which overrides RubyBasicObject#compareTo)
bfb2683
Thomas E Enebo enebo merged commit 93c81b3 into from
Thomas E Enebo enebo added this to the JRuby 1.7.12 milestone
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 12, 2014
  1. Daniel Marcotte

    Fix compare_to for to_java'ed Ruby objects

    dmarcotte authored
    Flip incorrect nil check which was resulting in #compare_to always
    returning 0 for many to_java'ed Ruby objects (anything not internally
    represented by a class which overrides RubyBasicObject#compareTo)
This page is out of date. Refresh to see the latest.
1  core/src/main/java/org/jruby/RubyBasicObject.java
View
@@ -1085,7 +1085,6 @@ public int compareTo(IRubyObject other) {
// if RubyBasicObject#op_cmp is used, the result may be nil
if (!cmp.isNil()) {
- } else {
return (int) cmp.convertToInteger().getLongValue();
}
} catch (RaiseException ex) {
11 spec/regression/GH-1520_java_compare_to_spec.rb
View
@@ -0,0 +1,11 @@
+require 'date'
+
+describe "java.lang.Object#compareTo" do
+ it "returns the appropriate value when invoked on a to_java'd object" do
+ # note: this bug only appeared for objects which were not represented internally with
+ # RubyBignum, RubyFixnum, RubyFloat or RubyString since they override the compareTo in RubyBasicObject
+ expect(Date.today.to_java.compareTo((Date.today - 1).to_java)).to eql(1)
+ expect(Date.today.to_java.compareTo((Date.today).to_java)).to eql(0)
+ expect(Date.today.to_java.compareTo((Date.today + 1).to_java)).to eql(-1)
+ end
+end
Something went wrong with that request. Please try again.