cloby
cloby copied to clipboard
cannot store Clojure::Object in Ref?
given the following code:
require 'rubygems'
require 'cloby'
Ref = Java::clojure.lang.Ref
class Foo < Clojure::Object
attr_accessor :count
def initialize(count = 1)
@count = count
end
def to_s
"[Foo #{count}]"
end
end
i get this:
jruby-1.6.6 :002 > foo = dosync { Foo.new }
=> [Foo 1]
jruby-1.6.6 :003 > ref = Ref.new(foo)
Java::JavaLang::IndexOutOfBoundsException:
from clojure.lang.PersistentVector.arrayFor(PersistentVector.java:106)
from clojure.lang.PersistentVector.nth(PersistentVector.java:110)
from org.jruby.clojure.ClojureLibrary$ClojureObject.getVariable(ClojureLibrary.java:46)
from org.jruby.RubyClass$VariableAccessor.get(RubyClass.java:253)
from org.jruby.RubyBasicObject.variableTableFetch(RubyBasicObject.java:1346)
from org.jruby.RubyBasicObject.variableTableFastFetch(RubyBasicObject.java:1356)
from org.jruby.RubyBasicObject.fastGetInternalVariable(RubyBasicObject.java:1447)
from org.jruby.RubyBasicObject.dataGetStruct(RubyBasicObject.java:978)
from org.jruby.RubyBasicObject.getJavaClass(RubyBasicObject.java:660)
from org.jruby.java.dispatch.CallableSelector.classHashCode(CallableSelector.java:418)
from org.jruby.java.dispatch.CallableSelector.argsHashCode(CallableSelector.java:388)
from org.jruby.java.dispatch.CallableSelector.matchingCallableArityOne(CallableSelector.java:50)
from org.jruby.java.invokers.RubyToJavaInvoker.findCallableArityOne(RubyToJavaInvoker.java:226)
from org.jruby.java.invokers.ConstructorInvoker.call(ConstructorInvoker.java:88)
from org.jruby.java.invokers.ConstructorInvoker.call(ConstructorInvoker.java:178)
from org.jruby.runtime.callsite.CachingCallSite.cacheAndCall(CachingCallSite.java:322)
... 138 levels...
from org.jruby.evaluator.ASTInterpreter.INTERPRET_METHOD(ASTInterpreter.java:75)
from org.jruby.internal.runtime.methods.InterpretedMethod.call(InterpretedMethod.java:190)
from org.jruby.internal.runtime.methods.DefaultMethod.call(DefaultMethod.java:199)
from org.jruby.runtime.callsite.CachingCallSite.cacheAndCall(CachingCallSite.java:312)
from org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:169)
from Users.tim.$_dot_rvm.rubies.jruby_minus_1_dot_6_dot_6.bin.irb.__file__(/Users/tim/.rvm/rubies/jruby-1.6.6/bin/irb:17)
from Users.tim.$_dot_rvm.rubies.jruby_minus_1_dot_6_dot_6.bin.irb.load(/Users/tim/.rvm/rubies/jruby-1.6.6/bin/irb)
from org.jruby.Ruby.runScript(Ruby.java:695)
from org.jruby.Ruby.runScript(Ruby.java:688)
from org.jruby.Ruby.runNormally(Ruby.java:595)
from org.jruby.Ruby.runFromMain(Ruby.java:444)
from org.jruby.Main.doRunFromMain(Main.java:344)
from org.jruby.Main.internalRun(Main.java:256)
from org.jruby.Main.run(Main.java:222)
from org.jruby.Main.run(Main.java:206)
from org.jruby.Main.main(Main.java:186)
jruby-1.6.6 :004 >
i added some debug output -- it turns out that ClojureObject.getVariable(-1) is called.
Ah-ha, I see. Why are you trying to store this in a Ref? Maybe I'm not understanding the use case...
the actual use case be an object graph that also includes collections (PersistentVector, for example) of ClojureObjects.
i just tried to boil it down as far as possible to nail the bug.
so, are you saying that a Clojure::Object does not belong in a ref, charlie? can you elaborate why not?
No, I'm not saying that...it's just not a case I had considered.
The bug here appears to be that we're not properly calculating the hashcode for your Foo class because there's some additional internal wiring needed for Clojure::Object types. I'll have a look.
Hmm, I just tried your example with cloby master and jruby master and did not get an error. Do you still get this?
yes, same error with jruby-head.
BTW, did you have a look a my bug fix? i simply copied two guard clauses over from RubyBasicObject, and for me this works.