On Sun, Apr 4, 2010 at 7:28 PM, Gergely N. [email protected] wrote:
I just distilled it to the snippets here: 355817’s gists · GitHub
Confirmed working on 1.5 and broken on 1.2, so that’s something:
~/projects/jruby âž” jruby -rjava array_bug.rb
Got bug.Food@1015a9e inspect: bug.Food@1015a9e class:Java::Food
javaclass:bug.Food
Digesting 3 of apple
Got bug.Food@1e45a5c inspect: bug.Food@1e45a5c class:Java::Food
javaclass:bug.Food
Digesting 999 of spam
~/projects/jruby âž” …/jruby-1.2.0/bin/jruby -rjava array_bug.rb
Got bug.Food@1be1041 inspect: #Java::JavaObject:0x11d2066
class:Java::JavaObject javaclass:bug.Food
1.2.0 can’t digest this, is it a bug?
Got bug.Food@d2b918 inspect: #Java::JavaObject:0x7616ad
class:Java::JavaObject javaclass:bug.Food
1.2.0 can’t digest this, is it a bug?
As mentioned there, this seems working since 1.4. This suggests to me
that my code was correct, and there is no need for any extra wrapping
code even with the ‘direct embedding’ case.
Actually the embedding mechanism doesn’t matter.
Yes, your code was probably right. I think I remember some bugs fixed
relating to getting elements out of Java arrays.
Here’s a workaround that might help you survive a bit longer:
require ‘jruby’
def feed
foods = []
Java::Food.feed(foods)
foods.each do |f|
puts “Got #{f} inspect: #{f.inspect} class:#{f.class}
javaclass:#{f.java_class}”
# JRuby.reference gives you a reference to the actual JavaObject
instance
# dataGetStruct gets the real object out of it, wrapping it
correctly
f = JRuby.reference(f).data_get_struct if Java::JavaObject === f
begin
f.digest
rescue NoMethodError
puts “#{JRUBY_VERSION} can’t digest this, is it a bug?”
end
end
end
I wouldn’t expect this to be very fast though. If you can, another
workaround is to use a real Java collection rather than a Ruby array:
def feed
food = java.util.ArrayList.new
…
Looks like the bug was in using a Ruby Array as a List, and things not
coercing right going into or coming out of it.
So, I wish I could upgrade… but a few things hold me off that, eg. an
exception like this:
“RuntimeError: Java wrapper with no contents”
when passing a block to a method taking a java.lang.Runnable.
Before I start debugging into this (and/or filing bugs for it): would
you have any ideas? in which cases would this happen?
This is on 1.4 I assume? It certainly should be working now. Have a
reproduction?
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email