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’
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?