-
Notifications
You must be signed in to change notification settings - Fork 4
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
Warning: "singleton on non-persistent Java type" with JRuby 1.7.4 #3
Comments
I can't seem to reproduce the warning. Here's what I've tried: # jruby-warning.rb
require 'bundler/setup'
require 'metaclass'
p java.lang.String.__metaclass__
If this really is a problem, we could (a) detect JRuby within the |
To be honest. Given that [1] http://ruby-doc.org/core-1.9.2/Object.html#method-i-singleton_class |
Thanks for looking into this. I was able to reproduce the issue by slightly modifying your test script: require 'rubygems' # didn't use Bundler
require 'metaclass'
p java.lang.String.new("test").__metaclass__ Results in:
Ruby version:
|
Hmm. This seems to be more fundamental than I first thought. Setting p java.lang.String.new("test").singleton_class
I'm not sure I can see a way around this other than explicitly setting java.lang.String.__persistent__ = true
p java.lang.String.new("test").singleton_class
Personally I think I'd be tempted to try to avoid stubbing the Java class directly - perhaps by wrapping it in some kind of Ruby adaptor class. Sorry - I hope that helps. |
That does help, thanks. I did manage to set module Metaclass::ObjectMethods
def __metaclass__
self.class.__persistent__ = true
class << self
self
end
end
end Digging deeper, it looks like we have this issue for another gem besides metaclass (https://github.com/apotonick/representable). So it seems that setting |
Oh. Cool. I'm not sure what I was doing (have deleted it), but whatever it was it was wrong! In order to come up with a better solution, I think we'd need to look in detail at how Mocha is using the singleton class and see whether we could store state in a different data structure as per the alternatives section on the JRuby wiki page. |
I think we ought to be able to use |
Hi,
I'm using mocha (and thus, this gem) on a JRuby 1.7.4 project which uses some Java classes.
It appears that line 4 of object_methods.rb triggers the following warning:
I did read the JRuby wiki about this: https://github.com/jruby/jruby/wiki/Persistence. But I'm not terribly sure what can be done in metaclass, if anything.
Any ideas? I don't think it's super-critical, but something to be aware of, perhaps.
Thanks!
/cc @kopchickm @karlj-spindance
The text was updated successfully, but these errors were encountered: