Charles A. Lanahan created JRUBY-6632: -----------------------------------------
Summary: BigDecimal.new fails when passed anything but string (Float, BigDecimal, Fixnum) Key: JRUBY-6632 URL: https://jira.codehaus.org/browse/JRUBY-6632 Project: JRuby Issue Type: Bug Components: Standard Library Affects Versions: JRuby 1.6.3, JRuby 1.7 Environment: Linux, 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) Reporter: Charles A. Lanahan Assignee: Thomas E Enebo 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) { 312 decimal = new BigDecimal(0); 313 } else { 314 String strValue = args[0].convertToString().toString(); 315 strValue = strValue.trim(); 316 if ("NaN".equals(strValue)) { 317 return newNaN(recv.getRuntime()); 318 } 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:~$ -- This message is automatically generated by JIRA. If you think it was sent incorrectly, please contact your JIRA administrators: https://jira.codehaus.org/secure/ContactAdministrators!default.jspa For more information on JIRA, see: http://www.atlassian.com/software/jira --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email