Details
-
Type:
Bug
-
Status:
Resolved
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: JRuby 1.6.3, JRuby 1.7.0.pre1
-
Fix Version/s: JRuby 1.7.0.RC1
-
Component/s: Standard Library
-
Labels:None
-
Environment:HideLinux,
daidoji@darkstar:~$ java -version
java version "1.6.0_25"
Java(TM) SE Runtime Environment (build 1.6.0_25-b06)
Java HotSpot(TM) Client VM (build 20.0-b11, mixed mode, sharing)ShowLinux, daidoji@darkstar :~$ java -version java version "1.6.0_25" Java(TM) SE Runtime Environment (build 1.6.0_25-b06) Java HotSpot(TM) Client VM (build 20.0-b11, mixed mode, sharing)
-
Number of attachments :
Description
Code below, According to documentation http://www.ruby-doc.org/stdlib-1.9.3/libdoc/bigdecimal/rdoc/BigDecimal.html#method-c-new should take any numeric type or string when creating a RubyBigDecimal object. However, Jruby fails on all of these. (Note: MRI seems to fail as well but for unrelated reasons I suppose https://gist.github.com/2552909).
Issue seems to be this code below in RubyBigDecimal.java. convertToString() is the line it fails on. Error that appears is from util/TypeConverter.java which RubyBasicObject.java uses to convert methods to string using the "to_str" method.
@JRubyMethod(name = "new", required = 1, optional = 1, meta = true)
309 public static RubyBigDecimal newInstance(IRubyObject recv, IRubyObject[] args) {
310 BigDecimal decimal;
311 if (args.length == 0)
else {
314 String strValue = args[0].convertToString().toString();
315 strValue = strValue.trim();
316 if ("NaN".equals(strValue))
daidoji@darkstar:~$ cat foo.rb
require 'bigdecimal'
a = BigDecimal(1.0)
b = BigDecimal(1)
c = BigDecimal(2/3)
d = BigDecimal(BigDecimal("1"))
daidoji@darkstar:~$ java -jar jruby/lib/jruby.jar -v
jruby 1.7.0.dev (ruby-1.9.3-p139) (2012-04-29 3b4ea85) (Java HotSpot(TM) Client VM 1.6.0_25) [linux-i386-java]
rubygems.rb not found; disabling gems
daidoji@darkstar:~$ java -jar jruby/lib/jruby.jar foo.rb
TypeError: can't convert Float into String
new at org/jruby/ext/bigdecimal/RubyBigDecimal.java:453
(root) at foo.rb:3
daidoji@darkstar:~$ vim foo.rb
Press ENTER or type command to continue
syntax=daidoji@darkstar:~$ java -jar jruby/lib/jruby.jar foo.rb
TypeError: can't convert Fixnum into String
new at org/jruby/ext/bigdecimal/RubyBigDecimal.java:453
(root) at foo.rb:4
daidoji@darkstar:~$ vim foo.rb
Press ENTER or type command to continue
syntax=daidoji@darkstar:~$ java -jar jruby/lib/jruby.jar foo.rb
TypeError: can't convert Fixnum into String
new at org/jruby/ext/bigdecimal/RubyBigDecimal.java:453
(root) at foo.rb:5
daidoji@darkstar:~$ vim foo.rb
Press ENTER or type command to continue
syntax=daidoji@darkstar:~$ java -jar jruby/lib/jruby.jar foo.rb
TypeError: can't convert BigDecimal into String
new at org/jruby/ext/bigdecimal/RubyBigDecimal.java:453
(root) at foo.rb:6
daidoji@darkstar:~$
Issue Links
- is duplicated by
-
JRUBY-6800
BigDecimal.new broken
-
-
JRUBY-6727
BigDecimal constructor doesn't work with floats
-
- relates to
-
JRUBY-6428
Regression: Float#to_d doesn't work on 1.7 (did in 1.6)
-
With your script failing, I'm not sure what it is we ought to fix. Can you try to turn this into a test case or spec that runs properly on Ruby 1.9.3? Once we have that, it should be trivial to fix the rest.