Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiplying BigDecimal with nil gives NullPointerException #2050

Closed
donv opened this issue Oct 16, 2014 · 6 comments
Closed

Multiplying BigDecimal with nil gives NullPointerException #2050

donv opened this issue Oct 16, 2014 · 6 comments
Assignees
Labels

Comments

@donv
Copy link
Member

donv commented Oct 16, 2014

Hi all!

I saw this was fixed for subtraction and division earlier: #1648, #1633, #1442, #1441

The exception is not caught by a rescue Exception and breaks our app.

This should probably be covered by a RubySpec?

With MRI 2.1.3:

reserve-pc:TelenorGS uwe$ irb
2.1.3 :001 > require 'bigdecimal'
 => true 
2.1.3 :003 > BigDecimal('1.23') * nil
TypeError: nil can't be coerced into BigDecimal
    from (irb):3:in `*'
    from (irb):3
    from /Users/uwe/.rvm/rubies/ruby-2.1.3/bin/irb:11:in `<main>'

With JRuby 1.7.16:

reserve-pc:TelenorGS uwe$ irb
jruby-1.7.16 :001 > require 'bigdecimal'
 => true 
jruby-1.7.16 :003 > BigDecimal('1.23')
 => #<BigDecimal:5b275dab,'0.123E1',3(4)> 
jruby-1.7.16 :004 > BigDecimal('1.23') * nil
Java::JavaLang::NullPointerException: 
    from org.jruby.ext.bigdecimal.RubyBigDecimal.cannotBeCoerced(RubyBigDecimal.java:428)
    from org.jruby.ext.bigdecimal.RubyBigDecimal.mult219(RubyBigDecimal.java:768)
    from org.jruby.ext.bigdecimal.RubyBigDecimal.op_mul19(RubyBigDecimal.java:755)
    from org.jruby.ext.bigdecimal.RubyBigDecimal$INVOKER$i$1$0$op_mul19.call(RubyBigDecimal$INVOKER$i$1$0$op_mul19.gen)
    from org.jruby.runtime.callsite.CachingCallSite.cacheAndCall(CachingCallSite.java:326)
    from org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:170)
    from org.jruby.runtime.callsite.MulCallSite.call(MulCallSite.java:38)
    from org.jruby.ast.CallOneArgNode.interpret(CallOneArgNode.java:57)
    from org.jruby.ast.NewlineNode.interpret(NewlineNode.java:105)
    from org.jruby.ast.RootNode.interpret(RootNode.java:129)
    from org.jruby.evaluator.ASTInterpreter.INTERPRET_EVAL(ASTInterpreter.java:95)
    from org.jruby.evaluator.ASTInterpreter.evalWithBinding(ASTInterpreter.java:184)
    from org.jruby.RubyKernel.evalCommon(RubyKernel.java:1138)
    from org.jruby.RubyKernel.eval19(RubyKernel.java:1101)
    from org.jruby.RubyKernel$INVOKER$s$0$3$eval19.call(RubyKernel$INVOKER$s$0$3$eval19.gen)
    from org.jruby.internal.runtime.methods.DynamicMethod.call(DynamicMethod.java:180)
... 116 levels...
    from org.jruby.ast.BlockNode.interpret(BlockNode.java:71)
    from org.jruby.evaluator.ASTInterpreter.INTERPRET_METHOD(ASTInterpreter.java:74)
    from org.jruby.internal.runtime.methods.InterpretedMethod.call(InterpretedMethod.java:182)
    from org.jruby.internal.runtime.methods.DefaultMethod.call(DefaultMethod.java:198)
    from org.jruby.runtime.callsite.CachingCallSite.cacheAndCall(CachingCallSite.java:326)
    from org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:170)
    from Users.uwe.$_dot_rvm.rubies.jruby_minus_1_dot_7_dot_16.bin.irb.__file__(/Users/uwe/.rvm/rubies/jruby-1.7.16/bin/irb:13)
    from Users.uwe.$_dot_rvm.rubies.jruby_minus_1_dot_7_dot_16.bin.irb.load(/Users/uwe/.rvm/rubies/jruby-1.7.16/bin/irb)
    from org.jruby.Ruby.runScript(Ruby.java:863)
    from org.jruby.Ruby.runScript(Ruby.java:856)
    from org.jruby.Ruby.runNormally(Ruby.java:725)
    from org.jruby.Ruby.runFromMain(Ruby.java:574)
    from org.jruby.Main.doRunFromMain(Main.java:395)
    from org.jruby.Main.internalRun(Main.java:290)
    from org.jruby.Main.run(Main.java:217)
    from org.jruby.Main.main(Main.java:197)
@donv donv added this to the JRuby 1.7.17 milestone Oct 16, 2014
@donv
Copy link
Member Author

donv commented Oct 16, 2014

Sorry, one mistake: The exception _CAN_ be caught by a rescue.

enebo added a commit that referenced this issue Nov 6, 2014
Fix for issue 2050 : BigDecimal and nil multiplication
@headius
Copy link
Member

headius commented Nov 13, 2014

Did you test this on master or 1.7? Because now 1.7 works and master fails :-)

@headius
Copy link
Member

headius commented Nov 13, 2014

It's possible that there are specs for this in the specs for rubysl-bigdecimal. The specs for all the rubysl gems no longer live in RubySpec...we need to stitch them together from the gem repos, I guess.

@headius
Copy link
Member

headius commented Nov 13, 2014

Fixed and test added to MRI's suite. We'll update tests more frequently.

@headius headius self-assigned this Nov 13, 2014
@k77ch7
Copy link
Contributor

k77ch7 commented Nov 13, 2014

@headius this issue should be reopened. In this case, the exception type should be TypeError.

on current master(336e527)

 $ jirb
irb(main):001:0> require 'bigdecimal'
=> true
irb(main):002:0> BigDecimal('1.23') * nil
ArgumentError: nil can't be coerced into BigDecimal
    from org/jruby/ext/bigdecimal/RubyBigDecimal.java:643:in `mult'
    from org/jruby/ext/bigdecimal/RubyBigDecimal.java:633:in `*'
    from (irb):2:in `evaluate'
    from org/jruby/RubyKernel.java:990:in `eval'
    from org/jruby/RubyKernel.java:1310:in `loop'
    from org/jruby/RubyKernel.java:1120:in `catch'
    from org/jruby/RubyKernel.java:1120:in `catch'
    from /Users/kiichi/git/jruby/bin/jirb:13:in `__script__'

@k77ch7
Copy link
Contributor

k77ch7 commented Nov 14, 2014

Current master(252bd4e) works.

$ jirb
irb(main):001:0> require 'bigdecimal'
=> true
irb(main):002:0> BigDecimal('1.23') * nil
TypeError: nil can't be coerced into BigDecimal
    from org/jruby/ext/bigdecimal/RubyBigDecimal.java:653:in `mult'
    from org/jruby/ext/bigdecimal/RubyBigDecimal.java:643:in `*'
    from (irb):2:in `evaluate'
    from org/jruby/RubyKernel.java:990:in `eval'
    from org/jruby/RubyKernel.java:1310:in `loop'
    from org/jruby/RubyKernel.java:1120:in `catch'
    from org/jruby/RubyKernel.java:1120:in `catch'
    from /Users/kiichi/git/jruby/bin/jirb:13:in `__script__'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants