IO#write breaks JRuby when writing object with special to_s implementation
--------------------------------------------------------------------------

                 Key: JRUBY-2044
                 URL: http://jira.codehaus.org/browse/JRUBY-2044
             Project: JRuby
          Issue Type: Bug
          Components: Core Classes/Modules
    Affects Versions: JRuby 1.1RC1
         Environment: Latest Jruby 1.1RC1
            Reporter: Vladimir Sizikov


Consider the example: 

{noformat}
file = File.open("/tmp/bbb", "w+")
obj = Object.new
def obj.to_s; nil; end
file.write(obj)
{noformat}

MRI handles this just fine.
JRuby breaks with java exception
Also, this happens when running rubyspecs, so it's important to fix.
And the fix is coming.

Exception in thread "main" java.lang.ClassCastException: org.jruby.RubyNil 
cannot be cast to org.jruby.RubyString
        at org.jruby.RubyIO.write(RubyIO.java:874)
        at org.jruby.RubyIOInvoker$write_method_1_0.call(Unknown Source)
        at 
org.jruby.internal.runtime.methods.JavaMethod$JavaMethodOne.call(JavaMethod.java:120)
        at 
org.jruby.internal.runtime.methods.DynamicMethod.call(DynamicMethod.java:65)
        at 
org.jruby.runtime.CallSite$InlineCachingCallSite.cacheAndCall(CallSite.java:166)
        at 
org.jruby.runtime.CallSite$InlineCachingCallSite.call(CallSite.java:301)
        at org.jruby.evaluator.ASTInterpreter.callNode(ASTInterpreter.java:657)
        at 
org.jruby.evaluator.ASTInterpreter.evalInternal(ASTInterpreter.java:303)
        at org.jruby.evaluator.ASTInterpreter.rootNode(ASTInterpreter.java:1607)
        at 
org.jruby.evaluator.ASTInterpreter.evalInternal(ASTInterpreter.java:453)
        at org.jruby.evaluator.ASTInterpreter.eval(ASTInterpreter.java:167)
        at 
org.jruby.evaluator.ASTInterpreter.evalWithBinding(ASTInterpreter.java:217)
        at org.jruby.RubyKernel.eval(RubyKernel.java:724)
        at org.jruby.RubyKernelInvoker$eval_method_1_3.call(Unknown Source)
        at 
org.jruby.internal.runtime.methods.DynamicMethod.call(DynamicMethod.java:65)
        at 
org.jruby.runtime.CallSite$InlineCachingCallSite.call(CallSite.java:298)
        at 
org.jruby.evaluator.ASTInterpreter.fCallNode(ASTInterpreter.java:1100)
        at 
org.jruby.evaluator.ASTInterpreter.evalInternal(ASTInterpreter.java:349)
        at org.jruby.evaluator.ASTInterpreter.eval(ASTInterpreter.java:167)
        at 
org.jruby.internal.runtime.methods.DefaultMethod.call(DefaultMethod.java:176)
        at 
org.jruby.internal.runtime.methods.DynamicMethod.call(DynamicMethod.java:65)
        at 
org.jruby.runtime.CallSite$InlineCachingCallSite.call(CallSite.java:298)
        at org.jruby.evaluator.ASTInterpreter.callNode(ASTInterpreter.java:657)
        at 
org.jruby.evaluator.ASTInterpreter.evalInternal(ASTInterpreter.java:303)
        at 
org.jruby.evaluator.ASTInterpreter.setupArgs(ASTInterpreter.java:2147)
        at 
org.jruby.evaluator.ASTInterpreter.fCallNode(ASTInterpreter.java:1095)
        at 
org.jruby.evaluator.ASTInterpreter.evalInternal(ASTInterpreter.java:349)
        at org.jruby.evaluator.ASTInterpreter.blockNode(ASTInterpreter.java:631)
        at 
org.jruby.evaluator.ASTInterpreter.evalInternal(ASTInterpreter.java:297)
        at org.jruby.evaluator.ASTInterpreter.eval(ASTInterpreter.java:167)
        at 
org.jruby.internal.runtime.methods.DefaultMethod.call(DefaultMethod.java:176)
        at 
org.jruby.internal.runtime.methods.DynamicMethod.call(DynamicMethod.java:65)
        at 
org.jruby.runtime.CallSite$InlineCachingCallSite.call(CallSite.java:298)
        at org.jruby.evaluator.ASTInterpreter.callNode(ASTInterpreter.java:657)
        at 
org.jruby.evaluator.ASTInterpreter.evalInternal(ASTInterpreter.java:303)
        at org.jruby.evaluator.ASTInterpreter.blockNode(ASTInterpreter.java:631)
        at 
org.jruby.evaluator.ASTInterpreter.evalInternal(ASTInterpreter.java:297)
        at 
org.jruby.evaluator.ASTInterpreter.rescueNode(ASTInterpreter.java:1509)
        at 
org.jruby.evaluator.ASTInterpreter.evalInternal(ASTInterpreter.java:447)
        at org.jruby.evaluator.ASTInterpreter.blockNode(ASTInterpreter.java:631)
        at 
org.jruby.evaluator.ASTInterpreter.evalInternal(ASTInterpreter.java:297)
        at org.jruby.evaluator.ASTInterpreter.eval(ASTInterpreter.java:167)
        at org.jruby.runtime.InterpretedBlock.yield(InterpretedBlock.java:153)
        at org.jruby.runtime.Block.yield(Block.java:114)
        at 
org.jruby.evaluator.ASTInterpreter.yieldNode(ASTInterpreter.java:1809)
        at 
org.jruby.evaluator.ASTInterpreter.evalInternal(ASTInterpreter.java:488)
        at 
org.jruby.evaluator.ASTInterpreter.ensureNode(ASTInterpreter.java:1072)
        at 
org.jruby.evaluator.ASTInterpreter.evalInternal(ASTInterpreter.java:343)
        at org.jruby.evaluator.ASTInterpreter.blockNode(ASTInterpreter.java:631)
        at 
org.jruby.evaluator.ASTInterpreter.evalInternal(ASTInterpreter.java:297)
        at org.jruby.evaluator.ASTInterpreter.eval(ASTInterpreter.java:167)
        at 
org.jruby.internal.runtime.methods.DefaultMethod.call(DefaultMethod.java:176)
        at 
org.jruby.runtime.CallSite$InlineCachingCallSite.call(CallSite.java:310)
        at 
org.jruby.evaluator.ASTInterpreter.fCallNode(ASTInterpreter.java:1105)
        at 
org.jruby.evaluator.ASTInterpreter.evalInternal(ASTInterpreter.java:349)
        at org.jruby.evaluator.ASTInterpreter.eval(ASTInterpreter.java:167)
        at org.jruby.runtime.InterpretedBlock.yield(InterpretedBlock.java:153)
        at org.jruby.runtime.Block.yield(Block.java:114)
        at 
org.jruby.evaluator.ASTInterpreter.yieldNode(ASTInterpreter.java:1809)
        at 
org.jruby.evaluator.ASTInterpreter.evalInternal(ASTInterpreter.java:488)
        at org.jruby.evaluator.ASTInterpreter.blockNode(ASTInterpreter.java:631)
        at 
org.jruby.evaluator.ASTInterpreter.evalInternal(ASTInterpreter.java:297)
        at 
org.jruby.evaluator.ASTInterpreter.rescueNode(ASTInterpreter.java:1509)
        at 
org.jruby.evaluator.ASTInterpreter.evalInternal(ASTInterpreter.java:447)
        at org.jruby.evaluator.ASTInterpreter.eval(ASTInterpreter.java:167)
        at org.jruby.runtime.InterpretedBlock.yield(InterpretedBlock.java:153)
        at org.jruby.runtime.InterpretedBlock.yield(InterpretedBlock.java:118)
        at org.jruby.runtime.Block.yield(Block.java:109)
        at org.jruby.RubyKernel.loop(RubyKernel.java:915)
        at org.jruby.RubyKernelInvoker$loop_method_0_0.call(Unknown Source)
        at 
org.jruby.internal.runtime.methods.JavaMethod$JavaMethodZeroBlock.call(JavaMethod.java:101)
        at 
org.jruby.runtime.CallSite$InlineCachingCallSite.cacheAndCall(CallSite.java:151)
        at 
org.jruby.runtime.CallSite$InlineCachingCallSite.call(CallSite.java:313)
        at 
org.jruby.evaluator.ASTInterpreter.fCallNode(ASTInterpreter.java:1105)
        at 
org.jruby.evaluator.ASTInterpreter.evalInternal(ASTInterpreter.java:349)
        at org.jruby.evaluator.ASTInterpreter.eval(ASTInterpreter.java:167)
        at org.jruby.runtime.InterpretedBlock.yield(InterpretedBlock.java:153)
        at org.jruby.runtime.InterpretedBlock.yield(InterpretedBlock.java:118)
        at org.jruby.runtime.Block.yield(Block.java:109)
        at org.jruby.RubyKernel.rbCatch(RubyKernel.java:753)
        at org.jruby.RubyKernelInvoker$rbCatch_method_1_0.call(Unknown Source)
        at 
org.jruby.internal.runtime.methods.JavaMethod$JavaMethodOneBlock.call(JavaMethod.java:139)
        at 
org.jruby.runtime.CallSite$InlineCachingCallSite.cacheAndCall(CallSite.java:151)
        at 
org.jruby.runtime.CallSite$InlineCachingCallSite.call(CallSite.java:313)
        at 
org.jruby.evaluator.ASTInterpreter.fCallNode(ASTInterpreter.java:1105)
        at 
org.jruby.evaluator.ASTInterpreter.evalInternal(ASTInterpreter.java:349)
        at org.jruby.evaluator.ASTInterpreter.blockNode(ASTInterpreter.java:631)
        at 
org.jruby.evaluator.ASTInterpreter.evalInternal(ASTInterpreter.java:297)
        at org.jruby.evaluator.ASTInterpreter.eval(ASTInterpreter.java:167)
        at 
org.jruby.internal.runtime.methods.DefaultMethod.call(DefaultMethod.java:176)
        at 
org.jruby.runtime.CallSite$InlineCachingCallSite.cacheAndCall(CallSite.java:151)
        at 
org.jruby.runtime.CallSite$InlineCachingCallSite.call(CallSite.java:313)
        at org.jruby.evaluator.ASTInterpreter.callNode(ASTInterpreter.java:662)
        at 
org.jruby.evaluator.ASTInterpreter.evalInternal(ASTInterpreter.java:303)
        at org.jruby.evaluator.ASTInterpreter.blockNode(ASTInterpreter.java:631)
        at 
org.jruby.evaluator.ASTInterpreter.evalInternal(ASTInterpreter.java:297)
        at org.jruby.evaluator.ASTInterpreter.eval(ASTInterpreter.java:167)
        at 
org.jruby.internal.runtime.methods.DefaultMethod.call(DefaultMethod.java:176)
        at 
org.jruby.internal.runtime.methods.DynamicMethod.call(DynamicMethod.java:65)
        at 
org.jruby.runtime.CallSite$InlineCachingCallSite.cacheAndCall(CallSite.java:166)
        at 
org.jruby.runtime.CallSite$InlineCachingCallSite.call(CallSite.java:301)
        at org.jruby.evaluator.ASTInterpreter.callNode(ASTInterpreter.java:657)
        at 
org.jruby.evaluator.ASTInterpreter.evalInternal(ASTInterpreter.java:303)
        at org.jruby.evaluator.ASTInterpreter.eval(ASTInterpreter.java:167)
        at org.jruby.runtime.InterpretedBlock.yield(InterpretedBlock.java:153)
        at org.jruby.runtime.InterpretedBlock.yield(InterpretedBlock.java:118)
        at org.jruby.runtime.Block.yield(Block.java:109)
        at org.jruby.RubyKernel.rbCatch(RubyKernel.java:753)
        at org.jruby.RubyKernelInvoker$rbCatch_method_1_0.call(Unknown Source)
        at 
org.jruby.internal.runtime.methods.JavaMethod$JavaMethodOneBlock.call(JavaMethod.java:139)
        at 
org.jruby.runtime.CallSite$InlineCachingCallSite.cacheAndCall(CallSite.java:151)
        at 
org.jruby.runtime.CallSite$InlineCachingCallSite.call(CallSite.java:313)
        at 
org.jruby.evaluator.ASTInterpreter.fCallNode(ASTInterpreter.java:1105)
        at 
org.jruby.evaluator.ASTInterpreter.evalInternal(ASTInterpreter.java:349)
        at org.jruby.evaluator.ASTInterpreter.blockNode(ASTInterpreter.java:631)
        at 
org.jruby.evaluator.ASTInterpreter.evalInternal(ASTInterpreter.java:297)
        at org.jruby.evaluator.ASTInterpreter.eval(ASTInterpreter.java:167)
        at 
org.jruby.internal.runtime.methods.DefaultMethod.call(DefaultMethod.java:176)
        at 
org.jruby.internal.runtime.methods.DynamicMethod.call(DynamicMethod.java:77)
        at 
org.jruby.runtime.CallSite$InlineCachingCallSite.cacheAndCall(CallSite.java:211)
        at 
org.jruby.runtime.CallSite$InlineCachingCallSite.call(CallSite.java:361)
        at 
ruby.opt.work.jruby_dot_git.bin.jirb.__file__(/opt/work/jruby/bin/jirb:13)
        at ruby.opt.work.jruby_dot_git.bin.jirb.load(/opt/work/jruby/bin/jirb)
        at org.jruby.Ruby.runScript(Ruby.java:489)
        at org.jruby.Ruby.runNormally(Ruby.java:409)
        at org.jruby.Ruby.runFromMain(Ruby.java:289)
        at org.jruby.Main.run(Main.java:142)
        at org.jruby.Main.run(Main.java:88)
        at org.jruby.Main.main(Main.java:79)


-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
http://jira.codehaus.org/secure/Administrators.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

Reply via email to