Uploaded image for project: 'RHEL'
  1. RHEL
  2. RHEL-5616

Lots of "already initialized constant" messages issued when rubygem-irb is used in scripts

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • None
    • rhel-9.2.0
    • ruby
    • None
    • Low
    • sst_cs_apps
    • ssg_core_services
    • 3
    • False
    • Hide

      None

      Show
      None
    • None
    • None
    • None
    • None
    • If docs needed, set a value
    • None

      Description of problem:

      Messages like this are issued when a ruby script uses "require 'irb'":

      /usr/share/ruby/irb/ruby-lex.rb:123: warning: already initialized constant RubyLex::ERROR_TOKENS
      /usr/share/gems/gems/irb-1.3.5/lib/irb/ruby-lex.rb:123: warning: previous definition of ERROR_TOKENS was here

      Version-Release number of selected component (if applicable):

      RHEL 9.2
      rubygem-irb-1.3.5-160.el9_0.noarch

      How reproducible:

      Always

      Steps to Reproduce:

      1. Install rubygem-irb

      1. yum install rubygem-irb

      2. Invoke irb via binding.irb

      $ ruby -e binding.irb

      Actual results:

      /usr/share/ruby/irb/ruby-lex.rb:123: warning: already initialized constant RubyLex::ERROR_TOKENS
      /usr/share/gems/gems/irb-1.3.5/lib/irb/ruby-lex.rb:123: warning: previous definition of ERROR_TOKENS was here
      /usr/share/ruby/irb/color.rb:8: warning: already initialized constant IRB::Color::CLEAR
      /usr/share/gems/gems/irb-1.3.5/lib/irb/color.rb:8: warning: previous definition of CLEAR was here
      /usr/share/ruby/irb/color.rb:9: warning: already initialized constant IRB::Color::BOLD
      /usr/share/gems/gems/irb-1.3.5/lib/irb/color.rb:9: warning: previous definition of BOLD was here
      /usr/share/ruby/irb/color.rb:10: warning: already initialized constant IRB::Color::UNDERLINE
      /usr/share/gems/gems/irb-1.3.5/lib/irb/color.rb:10: warning: previous definition of UNDERLINE was here
      /usr/share/ruby/irb/color.rb:11: warning: already initialized constant IRB::Color::REVERSE
      /usr/share/gems/gems/irb-1.3.5/lib/irb/color.rb:11: warning: previous definition of REVERSE was here
      /usr/share/ruby/irb/color.rb:12: warning: already initialized constant IRB::Color::RED
      /usr/share/gems/gems/irb-1.3.5/lib/irb/color.rb:12: warning: previous definition of RED was here
      /usr/share/ruby/irb/color.rb:13: warning: already initialized constant IRB::Color::GREEN
      /usr/share/gems/gems/irb-1.3.5/lib/irb/color.rb:13: warning: previous definition of GREEN was here
      /usr/share/ruby/irb/color.rb:14: warning: already initialized constant IRB::Color::YELLOW
      /usr/share/gems/gems/irb-1.3.5/lib/irb/color.rb:14: warning: previous definition of YELLOW was here
      /usr/share/ruby/irb/color.rb:15: warning: already initialized constant IRB::Color::BLUE
      /usr/share/gems/gems/irb-1.3.5/lib/irb/color.rb:15: warning: previous definition of BLUE was here
      /usr/share/ruby/irb/color.rb:16: warning: already initialized constant IRB::Color::MAGENTA
      /usr/share/gems/gems/irb-1.3.5/lib/irb/color.rb:16: warning: previous definition of MAGENTA was here
      /usr/share/ruby/irb/color.rb:17: warning: already initialized constant IRB::Color::CYAN
      /usr/share/gems/gems/irb-1.3.5/lib/irb/color.rb:17: warning: previous definition of CYAN was here
      /usr/share/ruby/irb/color.rb:19: warning: already initialized constant IRB::Color::TOKEN_KEYWORDS
      /usr/share/gems/gems/irb-1.3.5/lib/irb/color.rb:19: warning: previous definition of TOKEN_KEYWORDS was here
      /usr/share/ruby/irb/color.rb:26: warning: already initialized constant IRB::Color::ALL
      /usr/share/gems/gems/irb-1.3.5/lib/irb/color.rb:26: warning: previous definition of ALL was here
      /usr/share/ruby/irb/color.rb:32: warning: already initialized constant IRB::Color::TOKEN_SEQ_EXPRS
      /usr/share/gems/gems/irb-1.3.5/lib/irb/color.rb:32: warning: previous definition of TOKEN_SEQ_EXPRS was here
      /usr/share/ruby/irb/color.rb:75: warning: already initialized constant IRB::Color::ERROR_TOKENS
      /usr/share/gems/gems/irb-1.3.5/lib/irb/color.rb:75: warning: previous definition of ERROR_TOKENS was here
      irb(main):001:0>

      Expected results:

      No warning

      Additional info:

      The warnings appear because rubygThe messages appear because of the way ruby searches for libraries when
      "-r <library>" is passed. It looks at

      $ ruby -e 'puts $:'
      /usr/local/share/ruby/site_ruby
      /usr/local/lib64/ruby/site_ruby
      /usr/share/ruby/vendor_ruby
      /usr/lib64/ruby/vendor_ruby
      /usr/share/rubygems
      /usr/share/ruby
      /usr/lib64/ruby

      So it looks at /usr/share/ruby/, where the rubygem-irb package installs
      symbolic links to the files under /usr/share/gems/gems:

      $ file /usr/share/ruby/irb*
      /usr/share/ruby/irb: symbolic link to /usr/share/gems/gems/irb-1.3.5/lib/irb
      /usr/share/ruby/irb.rb: symbolic link to /usr/share/gems/gems/irb-1.3.5/lib/irb.rb

      But rubygem-irb adds a gemspec at /usr/share/gems/specifications/, so irb
      (and therefore color.rb) ends up loaded twice.

      In order to avoid this, you'd need to "load" irb, instead of "require" it as
      /usr/bin/irb does. Something like this:

      $ ruby -r rubygems -e "load Gem.activate_bin_path('irb', 'irb', '>= 0.a')"

      But this does not solve the problem with existing gems, e.g.

      1. yum install ruby-devel
      2. gem install rest-client -v 2.1.0
        Building native extensions. This could take a while...
        Successfully installed unf_ext-0.0.8.2
        Fetching unf-0.1.4.gem
        Successfully installed unf-0.1.4
        Fetching domain_name-0.5.20190701.gem
        Successfully installed domain_name-0.5.20190701
        Fetching http-cookie-1.0.5.gem
        Successfully installed http-cookie-1.0.5
        Fetching http-accept-1.7.0.gem
        Successfully installed http-accept-1.7.0
        Fetching rest-client-2.1.0.gem
        Successfully installed rest-client-2.1.0
        Parsing documentation for unf_ext-0.0.8.2
        Installing ri documentation for unf_ext-0.0.8.2
        Parsing documentation for unf-0.1.4
        Installing ri documentation for unf-0.1.4
        Parsing documentation for domain_name-0.5.20190701
        Installing ri documentation for domain_name-0.5.20190701
        Parsing documentation for http-cookie-1.0.5
        Installing ri documentation for http-cookie-1.0.5
        Parsing documentation for http-accept-1.7.0
        unknown encoding name "header" for lib/http/accept.rb, skipping
        Installing ri documentation for http-accept-1.7.0
        Parsing documentation for rest-client-2.1.0
        Installing ri documentation for rest-client-2.1.0
        Done installing documentation for unf_ext, unf, domain_name, http-cookie, http-accept, rest-client after 2 seconds
        6 gems installed

      $ which restclient
      /usr/local/bin/restclient
      [bashuser@rhel-9-1 ~]$ restclient
      /usr/local/share/gems/gems/rest-client-2.1.0/bin/restclient:64: warning: redefining Object#method_missing may cause infinite loop
      /usr/share/ruby/irb/ruby-lex.rb:123: warning: already initialized constant RubyLex::ERROR_TOKENS
      /usr/share/gems/gems/irb-1.3.5/lib/irb/ruby-lex.rb:123: warning: previous definition of ERROR_TOKENS was here
      /usr/share/ruby/irb/completion.rb:18: warning: already initialized constant IRB::InputCompletor::ReservedWords
      /usr/share/gems/gems/irb-1.3.5/lib/irb/completion.rb:18: warning: previous definition of ReservedWords was here
      /usr/share/ruby/irb/completion.rb:39: warning: already initialized constant IRB::InputCompletor::BASIC_WORD_BREAK_CHARACTERS
      /usr/share/gems/gems/irb-1.3.5/lib/irb/completion.rb:39: warning: previous definition of BASIC_WORD_BREAK_CHARACTERS was here
      /usr/share/ruby/irb/completion.rb:59: warning: already initialized constant IRB::InputCompletor::CompletionRequireProc
      /usr/share/gems/gems/irb-1.3.5/lib/irb/completion.rb:59: warning: previous definition of CompletionRequireProc was here
      /usr/share/ruby/irb/completion.rb:94: warning: already initialized constant IRB::InputCompletor::CompletionProc
      /usr/share/gems/gems/irb-1.3.5/lib/irb/completion.rb:94: warning: previous definition of CompletionProc was here
      /usr/share/ruby/irb/completion.rb:329: warning: already initialized constant IRB::InputCompletor::PerfectMatchedProc
      /usr/share/gems/gems/irb-1.3.5/lib/irb/completion.rb:329: warning: previous definition of PerfectMatchedProc was here
      /usr/share/ruby/irb/completion.rb:364: warning: already initialized constant IRB::InputCompletor::Operators
      /usr/share/gems/gems/irb-1.3.5/lib/irb/completion.rb:364: warning: previous definition of Operators was here
      /usr/share/ruby/irb/color.rb:8: warning: already initialized constant IRB::Color::CLEAR
      /usr/share/gems/gems/irb-1.3.5/lib/irb/color.rb:8: warning: previous definition of CLEAR was here
      /usr/share/ruby/irb/color.rb:9: warning: already initialized constant IRB::Color::BOLD
      /usr/share/gems/gems/irb-1.3.5/lib/irb/color.rb:9: warning: previous definition of BOLD was here
      /usr/share/ruby/irb/color.rb:10: warning: already initialized constant IRB::Color::UNDERLINE
      /usr/share/gems/gems/irb-1.3.5/lib/irb/color.rb:10: warning: previous definition of UNDERLINE was here
      /usr/share/ruby/irb/color.rb:11: warning: already initialized constant IRB::Color::REVERSE
      /usr/share/gems/gems/irb-1.3.5/lib/irb/color.rb:11: warning: previous definition of REVERSE was here
      /usr/share/ruby/irb/color.rb:12: warning: already initialized constant IRB::Color::RED
      /usr/share/gems/gems/irb-1.3.5/lib/irb/color.rb:12: warning: previous definition of RED was here
      /usr/share/ruby/irb/color.rb:13: warning: already initialized constant IRB::Color::GREEN
      /usr/share/gems/gems/irb-1.3.5/lib/irb/color.rb:13: warning: previous definition of GREEN was here
      /usr/share/ruby/irb/color.rb:14: warning: already initialized constant IRB::Color::YELLOW
      /usr/share/gems/gems/irb-1.3.5/lib/irb/color.rb:14: warning: previous definition of YELLOW was here
      /usr/share/ruby/irb/color.rb:15: warning: already initialized constant IRB::Color::BLUE
      /usr/share/gems/gems/irb-1.3.5/lib/irb/color.rb:15: warning: previous definition of BLUE was here
      /usr/share/ruby/irb/color.rb:16: warning: already initialized constant IRB::Color::MAGENTA
      /usr/share/gems/gems/irb-1.3.5/lib/irb/color.rb:16: warning: previous definition of MAGENTA was here
      /usr/share/ruby/irb/color.rb:17: warning: already initialized constant IRB::Color::CYAN
      /usr/share/gems/gems/irb-1.3.5/lib/irb/color.rb:17: warning: previous definition of CYAN was here
      /usr/share/ruby/irb/color.rb:19: warning: already initialized constant IRB::Color::TOKEN_KEYWORDS
      /usr/share/gems/gems/irb-1.3.5/lib/irb/color.rb:19: warning: previous definition of TOKEN_KEYWORDS was here
      /usr/share/ruby/irb/color.rb:26: warning: already initialized constant IRB::Color::ALL
      /usr/share/gems/gems/irb-1.3.5/lib/irb/color.rb:26: warning: previous definition of ALL was here
      /usr/share/ruby/irb/color.rb:32: warning: already initialized constant IRB::Color::TOKEN_SEQ_EXPRS
      /usr/share/gems/gems/irb-1.3.5/lib/irb/color.rb:32: warning: previous definition of TOKEN_SEQ_EXPRS was here
      /usr/share/ruby/irb/color.rb:75: warning: already initialized constant IRB::Color::ERROR_TOKENS
      /usr/share/gems/gems/irb-1.3.5/lib/irb/color.rb:75: warning: previous definition of ERROR_TOKENS was here

            ruby-maint ruby-maint
            rhn-support-casantos Carlos Santos
            ruby-maint ruby-maint
            bot rhel-cs-apps-subsystem-qe bot rhel-cs-apps-subsystem-qe
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: