tags:

views:

66

answers:

2

I'm using the ruby-mysql library under JRuby and get the following warnings:

/mysql/protocol.rb:530 warning: GC.disable does nothing on JRuby

Is there any way to get JRuby to stop complaining about this?

+2  A: 

You have a couple options.

First, you can run your program with the -W0 option which will disable all warnings. That's probably not what you want.

However, applying -W0 is the same as setting $VERBOSE to nil -- so we can simply do that around the code where we want to suppress warnings. This is the second and much more preferable option.

def suppress_all_warnings
  old_verbose = $VERBOSE
  begin
    $VERBOSE = nil
    yield if block_given?
  ensure
    # always re-set to old value, even if block raises an exception
    $VERBOSE = old_verbose
  end
end

puts "Starting"
MyConst = 1
MyConst = 2
suppress_all_warnings do
  GC.disable
end
puts "Done"

Running this with JRuby 1.5.0 correctly warns me about the reinitialized constant and correctly suppresses the GC.disable warning.

Mark Rushakoff
Very good and informative answer. Thanks!
makenai
+1  A: 

If you switch from ruby-mysql to activerecord-jdbcmysql-adapter, you can avoid this warning entirely.

John Douthat