ClassCastException when subclassing Queue

Hi All,

I’m getting a strange error with JRuby 1.5.3 Did not have this problem
with
1.1.6 (I’ve not upgraded in a while, alas). Perhaps it’s my own fault,
and
woudl appreciate some help.

The following code shows the error:

require ‘java’
require ‘thread’

class MyQueue < Queue
include Java::javax.management.DynamicMBean
end

mq = MyQueue.new
puts mq.size

The act of including DynamicMBean is the culprit, it seems. I’d used
this
with JRuby 1.1.6 to build a JMX-instrumented Queue. Now, when I run
this
snippet, I get:

org/jruby/libraries/ThreadLibrary$Queue$i_method_0_0$RUBYINVOKER$length.gen:65535:in
call': java.lang.ClassCastExcept\ ion: MyQueue_1542986935 cannot be cast to org.jruby.libraries.ThreadLibrary$Queue from CachingCallSite.java:289:incacheAndCall’
from CachingCallSite.java:108:in call' from queue.rb:8:infile
from queue.rb:-1:in load' from Ruby.java:686:inrunScript’
from Ruby.java:569:in runNormally' from Ruby.java:415:inrunFromMain’
from Main.java:286:in run' from Main.java:128:inrun’
from Main.java:97:in `main’

Anyone got help to offer? I’m flummoxed.

Cheers,
–Bob

Replying to myself, I’ve investigated a little more. It’s not dependent
on
the DynamicMBean. It appears that including anything with Queue
causes
the problem. For example, the following shows the same behavior:


require ‘java’
require ‘thread’

class RunnableQueue < Queue
include Java::java.lang.Runnable
end

puts “Trying a Runnable queue”
puts RunnableQueue.new.size


I get the same ClassCastException. I am right, aren’t I, that the
construct
"include " is how I should declare that a class
implements
said interface?

What am I doing wrong?

Cheers,
–Bob

So … I’ve convinced myself that this is a Jruby 1.5 bug. What is the
procedure for reporting this?

Can anyone suggest a work-around? Perhaps this is a good opportunity
for me
tl learn about Delegates.

Cheers,
–Bob

On Wed, Oct 27, 2010 at 12:50 PM, Bob W.
[email protected] wrote:

So … I’ve convinced myself that this is a Jruby 1.5 bug. What is the
procedure for reporting this?

Please file one at http://bugs.jruby.org/.

Can anyone suggest a work-around? Perhaps this is a good opportunity for me
tl learn about Delegates.

Delegates would certainly be a good way to accomplish this.

/Nick

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs