Skip to content

Fix #295: Ignore Java package reference objects in JRuby - #403

Merged
hsbt merged 1 commit into
ruby:masterfrom
byteit101:master
Nov 17, 2022
Merged

hsbt merged 1 commit into
ruby:masterfrom
byteit101:master

Conversation

@byteit101

Copy link
Copy Markdown
Contributor

Ignore modules that don't have instance_methods on them. The same logic can be found in Pry to accommodate core JRuby features. Fixes #295

@ccutrer ccutrer left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this won't work (for this particular use case):

irb(main):002:0> java.lang.respond_to?(:instance_methods)
=> true

jruby/jruby#7390 definitely will, though.

@byteit101

Copy link
Copy Markdown
Contributor Author

@ccutrer What version of jruby are you using? I get nil

@ccutrer

ccutrer commented Oct 1, 2022

Copy link
Copy Markdown
Contributor

@ccutrer What version of jruby are you using? I get nil

jruby 9.3.8.0 (2.6.8) 2022-09-13 98d69c9461 OpenJDK 64-Bit Server VM 11.0.16+8-post-Ubuntu-0ubuntu122.04 on 11.0.16+8-post-Ubuntu-0ubuntu122.04 +jit [x86_64-linux]

@ccutrer

ccutrer commented Oct 1, 2022

Copy link
Copy Markdown
Contributor

oh wait, duh, that's cause I have my .irbrc workaround in :). ignore me!

@byteit101

Copy link
Copy Markdown
Contributor Author

Oh phew, I was about to check if you were the person who filed that issue as I just re-tested in 9.1, 9.2, 9.3, and 9.4-SNAPSHOT and got nil on all and was very confused

@hsbt

hsbt commented Oct 5, 2022

Copy link
Copy Markdown
Member

Should we ignore them only JRuby? If It's yes, Can you add the condition of RUBY_ENGINE?

@byteit101

Copy link
Copy Markdown
Contributor Author

It's possible to create IRB-breaking objects on MRI & TruffleRuby too:

module Weird
  class << self
    undef :instance_methods
  end
end

As such, while JRuby had lots of them by default, I'm hesitant to add an engine check only for JRuby. If you think this isn't a concern though, I could add the check.

3.0.0 :001 > module Weird; class << self; undef :instance_methods; end; end
 => nil 
3.0.0 :002 > ab./home/byteit101/.rvm/gems/ruby-3.0.0/gems/irb-1.4.2/lib/irb/completion.rb:354:in `block in retrieve_completion_data': undefined method `instance_methods' for Weird:Module (NoMethodError)
Did you mean?  instance_method
        from /home/byteit101/.rvm/gems/ruby-3.0.0/gems/irb-1.4.2/lib/irb/completion.rb:352:in `each_object'
        from /home/byteit101/.rvm/gems/ruby-3.0.0/gems/irb-1.4.2/lib/irb/completion.rb:352:in `retrieve_completion_data'
        from /home/byteit101/.rvm/gems/ruby-3.0.0/gems/irb-1.4.2/lib/irb/completion.rb:159:in `block in <module:InputCompletor>'
[snip...]

@headius

headius commented Oct 13, 2022

Copy link
Copy Markdown
Contributor

This is moot now that we exclude our package modules from each_object(Module), correct?

@byteit101

Copy link
Copy Markdown
Contributor Author

Well, I can still crash IRB on both JRuby and CRuby, so no this isn't moot. The most common case was taken care of yes, but I'd like to prevent IRB crashes

@headius

headius commented Oct 13, 2022

Copy link
Copy Markdown
Contributor

I understand now: there's still an issue if you create - from Ruby code - a similar module that does not respond to the methods that IRB requires, and this affects any Ruby implementation running IRB.

@hsbt
hsbt merged commit 84d0301 into ruby:master Nov 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ArgumentError & exit while typing in IRB on JRuby 9.3

4 participants