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

cannot store Clojure::Object in Ref? #3

Open
tlossen opened this issue Feb 23, 2012 · 7 comments
Open

cannot store Clojure::Object in Ref? #3

tlossen opened this issue Feb 23, 2012 · 7 comments

Comments

@tlossen
Copy link

tlossen commented Feb 23, 2012

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 >
@tlossen
Copy link
Author

tlossen commented Feb 23, 2012

i added some debug output -- it turns out that ClojureObject.getVariable(-1) is called.

@headius
Copy link
Owner

headius commented Feb 23, 2012

Ah-ha, I see. Why are you trying to store this in a Ref? Maybe I'm not understanding the use case...

@tlossen
Copy link
Author

tlossen commented Feb 23, 2012

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.

@tlossen
Copy link
Author

tlossen commented Mar 12, 2012

so, are you saying that a Clojure::Object does not belong in a ref, charlie? can you elaborate why not?

@headius
Copy link
Owner

headius commented Mar 12, 2012

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.

@headius
Copy link
Owner

headius commented Mar 12, 2012

Hmm, I just tried your example with cloby master and jruby master and did not get an error. Do you still get this?

@tlossen
Copy link
Author

tlossen commented Mar 14, 2012

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.

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

No branches or pull requests

2 participants