Uploaded image for project: 'Ruby Driver'
  1. Ruby Driver
  2. RUBY-1189

BSON on JRuby - ByteBuf#getInt64 should return Fixnum not Bignum

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • bson-4.2.1
    • Affects Version/s: bson-4.2.0
    • Component/s: BSON
    • Labels:
      None
    • Environment:
      JRuby 1.7/9k

      org.bson.ByteBuf#getInt64 method should not return Bignum when it
      is in range covered by Fixnum (long is always covered by Fixnum).
      On MRI it is not possible to create Bignum in range of Fixnum,
      but Java extension does it:
      https://github.com/mongodb/bson-ruby/blob/master/src/main/org/bson/ByteBuf.java#L261
      It wont be fixed on JRuby.

      This leads to unexpected behaviour: http://pastie.org/10978801#1,14,17,19,25
      #jruby IRC discussion: https://logs.jruby.org/jruby/2016-12-07#18357998;

      require "bundler/inline"
      
      gemfile(true) do
        source "https://rubygems.org"
        gem "mongo", "= 2.4.0"
      end
      
      Mongo::VERSION
      #=> "2.4.0"
      BSON::VERSION
      #=> "4.2.0"
      
      client = Mongo::Client.new(["127.0.0.1:27017"], database: "bignum_test")
      
      id = 2400000017
      id.class
      #=> Fixnum
      
      client[:test].insert_one(_id: id)
      doc = client[:test].find().first()
      
      RUBY_DESCRIPTION
      #=> "jruby 9.1.6.0 (2.3.1) 2016-11-09 0150a76 Java HotSpot(TM) 64-Bit Server VM 25.91-b14 on 1.8.0_91-b14 [darwin-x86_64]"
      
      doc["_id"].class
      #=> Bignum
      
      RUBY_DESCRIPTION
      #=> "ruby 2.3.3p222 (2016-11-21 revision 56859) [x86_64-darwin15]"
      
      doc["_id"].class
      #=> Fixnum
      

            Assignee:
            emily.stolfo Emily Stolfo
            Reporter:
            kamil.lemanski@nokaut.pl Kamil Lema?ski
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: