Junho Park Junho Park - 2 months ago 6
Ruby Question

When calling SonarQube API - /api/properties?format=json - results in a Ruby error

I'm attempting to set up the SonarLint IntelliJ IDEA plugin (plugin for SonarQube) and it's failing due to a 500 response when the plugin calls the following URL:

/api/properties?format=json


When I go to either
/api/properties
or
/api/properties?format=xml
in my browser, things look okay. However, when I go to
/api/properties?format=json
I see the following in my sonar.log file:

2016.10.03 09:37:22 ERROR web[o.s.s.ui.JRubyFacade] Fail to render: http://jenkins.aws.cappex.com:9000/api/properties?format=json
undefined method 'generate' for #<JSON::Ext::Generator::State:0x344bc254>
/usr/local/rvm/gems/ruby-1.9.3-p551@global/gems/json-1.8.1/lib/json/common.rb:223:in 'generate'
/usr/local/rvm/gems/ruby-1.9.3-p551@global/gems/json-1.8.1/lib/json/common.rb:470:in 'JSON'
/etc/sonarqube/web/WEB-INF/app/controllers/api/api_controller.rb:48:in 'jsonp'
/etc/sonarqube/web/WEB-INF/app/controllers/api/properties_controller.rb:62:in 'index'
org/jruby/RubyProc.java:290:in 'call'
org/jruby/RubyProc.java:224:in 'call'
/etc/sonarqube/web/WEB-INF/gems/gems/actionpack-2.3.15/lib/action_controller/mime_responds.rb:135:in 'custom'
org/jruby/RubyProc.java:290:in 'call'
org/jruby/RubyProc.java:224:in 'call'
/etc/sonarqube/web/WEB-INF/gems/gems/actionpack-2.3.15/lib/action_controller/mime_responds.rb:179:in 'respond'
org/jruby/RubyArray.java:1613:in 'each'
/etc/sonarqube/web/WEB-INF/gems/gems/actionpack-2.3.15/lib/action_controller/mime_responds.rb:173:in 'respond'
/etc/sonarqube/web/WEB-INF/gems/gems/actionpack-2.3.15/lib/action_controller/mime_responds.rb:107:in 'respond_to'
/etc/sonarqube/web/WEB-INF/app/controllers/api/properties_controller.rb:61:in 'index'
org/jruby/RubyKernel.java:2223:in 'send'
/etc/sonarqube/web/WEB-INF/gems/gems/actionpack-2.3.15/lib/action_controller/base.rb:1333:in 'perform_action'
/etc/sonarqube/web/WEB-INF/gems/gems/actionpack-2.3.15/lib/action_controller/filters.rb:617:in 'call_filters'
/etc/sonarqube/web/WEB-INF/gems/gems/actionpack-2.3.15/lib/action_controller/filters.rb:610:in 'perform_action_with_filters'
/etc/sonarqube/web/WEB-INF/gems/gems/actionpack-2.3.15/lib/action_controller/benchmarking.rb:68:in 'perform_action_with_benchmark'
/etc/sonarqube/web/WEB-INF/gems/gems/activesupport-2.3.15/lib/active_support/core_ext/benchmark.rb:17:in 'ms'
jar:file:/etc/sonarqube/lib/server/jruby-complete-1.7.9.jar!/META-INF/jruby.home/lib/ruby/1.8/benchmark.rb:308:in 'realtime'
/etc/sonarqube/web/WEB-INF/gems/gems/activesupport-2.3.15/lib/active_support/core_ext/benchmark.rb:17:in 'ms'
/etc/sonarqube/web/WEB-INF/gems/gems/actionpack-2.3.15/lib/action_controller/benchmarking.rb:68:in 'perform_action_with_benchmark'
/etc/sonarqube/web/WEB-INF/gems/gems/actionpack-2.3.15/lib/action_controller/rescue.rb:160:in 'perform_action_with_rescue'
/etc/sonarqube/web/WEB-INF/gems/gems/actionpack-2.3.15/lib/action_controller/flash.rb:151:in 'perform_action_with_flash'
org/jruby/RubyKernel.java:2223:in 'send'
/etc/sonarqube/web/WEB-INF/gems/gems/actionpack-2.3.15/lib/action_controller/base.rb:532:in 'process'
/etc/sonarqube/web/WEB-INF/gems/gems/actionpack-2.3.15/lib/action_controller/filters.rb:606:in 'process_with_filters'
/etc/sonarqube/web/WEB-INF/gems/gems/actionpack-2.3.15/lib/action_controller/base.rb:391:in 'process'
/etc/sonarqube/web/WEB-INF/gems/gems/actionpack-2.3.15/lib/action_controller/base.rb:386:in 'call'
/etc/sonarqube/web/WEB-INF/gems/gems/actionpack-2.3.15/lib/action_controller/routing/route_set.rb:450:in 'call'
/etc/sonarqube/web/WEB-INF/gems/gems/actionpack-2.3.15/lib/action_controller/dispatcher.rb:87:in 'dispatch'
/etc/sonarqube/web/WEB-INF/gems/gems/actionpack-2.3.15/lib/action_controller/dispatcher.rb:85:in 'dispatch'
/etc/sonarqube/web/WEB-INF/gems/gems/actionpack-2.3.15/lib/action_controller/dispatcher.rb:121:in '_call'
/etc/sonarqube/web/WEB-INF/gems/gems/actionpack-2.3.15/lib/action_controller/dispatcher.rb:130:in 'build_middleware_stack'
org/jruby/RubyProc.java:290:in 'call'
org/jruby/RubyProc.java:224:in 'call'
/etc/sonarqube/web/WEB-INF/gems/gems/activerecord-2.3.15/lib/active_record/query_cache.rb:29:in 'call'
/etc/sonarqube/web/WEB-INF/gems/gems/activerecord-2.3.15/lib/active_record/connection_adapters/abstract/query_cache.rb:34:in 'cache'
/etc/sonarqube/web/WEB-INF/gems/gems/activerecord-2.3.15/lib/active_record/query_cache.rb:9:in 'cache'
/etc/sonarqube/web/WEB-INF/gems/gems/activerecord-2.3.15/lib/active_record/query_cache.rb:28:in 'call'
/etc/sonarqube/web/WEB-INF/gems/gems/activerecord-2.3.15/lib/active_record/connection_adapters/abstract/connection_pool.rb:361:in 'call'
/etc/sonarqube/web/WEB-INF/config/environment.rb:67:in 'call'
/etc/sonarqube/web/WEB-INF/gems/gems/actionpack-2.3.15/lib/action_controller/string_coercion.rb:25:in 'call'
/etc/sonarqube/web/WEB-INF/gems/gems/rack-1.1.6/lib/rack/head.rb:9:in 'call'
/etc/sonarqube/web/WEB-INF/gems/gems/rack-1.1.6/lib/rack/methodoverride.rb:24:in 'call'
/etc/sonarqube/web/WEB-INF/gems/gems/actionpack-2.3.15/lib/action_controller/params_parser.rb:15:in 'call'
file:/etc/sonarqube/lib/server/jruby-rack-1.1.13.2.jar!/jruby/rack/session_store.rb:70:in 'context'
/etc/sonarqube/web/WEB-INF/gems/gems/rack-1.1.6/lib/rack/session/abstract/id.rb:58:in 'call'
/etc/sonarqube/web/WEB-INF/gems/gems/actionpack-2.3.15/lib/action_controller/failsafe.rb:26:in 'call'
/etc/sonarqube/web/WEB-INF/gems/gems/actionpack-2.3.15/lib/action_controller/dispatcher.rb:106:in 'call'
file:/etc/sonarqube/lib/server/jruby-rack-1.1.13.2.jar!/rack/adapter/rails.rb:34:in 'serve_rails'
file:/etc/sonarqube/lib/server/jruby-rack-1.1.13.2.jar!/rack/adapter/rails.rb:39:in 'call'
file:/etc/sonarqube/lib/server/jruby-rack-1.1.13.2.jar!/rack/handler/servlet.rb:22:in 'call'

2016.10.03 09:37:22 ERROR web[o.s.s.ui.JRubyFacade] Fail to render: http://jenkins.aws.cappex.com:9000/api/properties?format=json
undefined method 'generate' for #<JSON::Ext::Generator::State:0x183f78a8>
/usr/local/rvm/gems/ruby-1.9.3-p551@global/gems/json-1.8.1/lib/json/common.rb:223:in 'generate'
/usr/local/rvm/gems/ruby-1.9.3-p551@global/gems/json-1.8.1/lib/json/common.rb:470:in 'JSON'
/etc/sonarqube/web/WEB-INF/app/controllers/api/api_controller.rb:48:in 'jsonp'
/etc/sonarqube/web/WEB-INF/app/controllers/api/api_controller.rb:132:in 'error_to_json'
/etc/sonarqube/web/WEB-INF/app/controllers/api/api_controller.rb:123:in 'render_response'
org/jruby/RubyProc.java:290:in 'call'
org/jruby/RubyProc.java:224:in 'call'
/etc/sonarqube/web/WEB-INF/gems/gems/actionpack-2.3.15/lib/action_controller/mime_responds.rb:135:in 'custom'
org/jruby/RubyProc.java:290:in 'call'
org/jruby/RubyProc.java:224:in 'call'
/etc/sonarqube/web/WEB-INF/gems/gems/actionpack-2.3.15/lib/action_controller/mime_responds.rb:179:in 'respond'
org/jruby/RubyArray.java:1613:in 'each'
/etc/sonarqube/web/WEB-INF/gems/gems/actionpack-2.3.15/lib/action_controller/mime_responds.rb:173:in 'respond'
/etc/sonarqube/web/WEB-INF/gems/gems/actionpack-2.3.15/lib/action_controller/mime_responds.rb:107:in 'respond_to'
/etc/sonarqube/web/WEB-INF/app/controllers/api/api_controller.rb:122:in 'render_response'
/etc/sonarqube/web/WEB-INF/app/controllers/api/api_controller.rb:85:in 'render_error'
org/jruby/RubyMethod.java:128:in 'call'
/etc/sonarqube/web/WEB-INF/gems/gems/activesupport-2.3.15/lib/active_support/rescuable.rb:73:in 'rescue_with_handler'
/etc/sonarqube/web/WEB-INF/gems/gems/actionpack-2.3.15/lib/action_controller/rescue.rb:73:in 'rescue_action'
/etc/sonarqube/web/WEB-INF/gems/gems/actionpack-2.3.15/lib/action_controller/rescue.rb:162:in 'perform_action_with_rescue'
/etc/sonarqube/web/WEB-INF/gems/gems/actionpack-2.3.15/lib/action_controller/rescue.rb:160:in 'perform_action_with_rescue'
/etc/sonarqube/web/WEB-INF/gems/gems/actionpack-2.3.15/lib/action_controller/flash.rb:151:in 'perform_action_with_flash'
org/jruby/RubyKernel.java:2223:in 'send'
/etc/sonarqube/web/WEB-INF/gems/gems/actionpack-2.3.15/lib/action_controller/base.rb:532:in 'process'
/etc/sonarqube/web/WEB-INF/gems/gems/actionpack-2.3.15/lib/action_controller/filters.rb:606:in 'process_with_filters'
/etc/sonarqube/web/WEB-INF/gems/gems/actionpack-2.3.15/lib/action_controller/base.rb:391:in 'process'
/etc/sonarqube/web/WEB-INF/gems/gems/actionpack-2.3.15/lib/action_controller/base.rb:386:in 'call'
/etc/sonarqube/web/WEB-INF/gems/gems/actionpack-2.3.15/lib/action_controller/routing/route_set.rb:450:in 'call'
/etc/sonarqube/web/WEB-INF/gems/gems/actionpack-2.3.15/lib/action_controller/dispatcher.rb:87:in 'dispatch'
/etc/sonarqube/web/WEB-INF/gems/gems/actionpack-2.3.15/lib/action_controller/dispatcher.rb:85:in 'dispatch'
/etc/sonarqube/web/WEB-INF/gems/gems/actionpack-2.3.15/lib/action_controller/dispatcher.rb:121:in '_call'
/etc/sonarqube/web/WEB-INF/gems/gems/actionpack-2.3.15/lib/action_controller/dispatcher.rb:130:in 'build_middleware_stack'
org/jruby/RubyProc.java:290:in 'call'
org/jruby/RubyProc.java:224:in 'call'
/etc/sonarqube/web/WEB-INF/gems/gems/activerecord-2.3.15/lib/active_record/query_cache.rb:29:in 'call'
/etc/sonarqube/web/WEB-INF/gems/gems/activerecord-2.3.15/lib/active_record/connection_adapters/abstract/query_cache.rb:34:in 'cache'
/etc/sonarqube/web/WEB-INF/gems/gems/activerecord-2.3.15/lib/active_record/query_cache.rb:9:in 'cache'
/etc/sonarqube/web/WEB-INF/gems/gems/activerecord-2.3.15/lib/active_record/query_cache.rb:28:in 'call'
/etc/sonarqube/web/WEB-INF/gems/gems/activerecord-2.3.15/lib/active_record/connection_adapters/abstract/connection_pool.rb:361:in 'call'
/etc/sonarqube/web/WEB-INF/config/environment.rb:67:in 'call'
/etc/sonarqube/web/WEB-INF/gems/gems/actionpack-2.3.15/lib/action_controller/string_coercion.rb:25:in 'call'
/etc/sonarqube/web/WEB-INF/gems/gems/rack-1.1.6/lib/rack/head.rb:9:in 'call'
/etc/sonarqube/web/WEB-INF/gems/gems/rack-1.1.6/lib/rack/methodoverride.rb:24:in 'call'
/etc/sonarqube/web/WEB-INF/gems/gems/actionpack-2.3.15/lib/action_controller/params_parser.rb:15:in 'call'
file:/etc/sonarqube/lib/server/jruby-rack-1.1.13.2.jar!/jruby/rack/session_store.rb:70:in 'context'
/etc/sonarqube/web/WEB-INF/gems/gems/rack-1.1.6/lib/rack/session/abstract/id.rb:58:in 'call'
/etc/sonarqube/web/WEB-INF/gems/gems/actionpack-2.3.15/lib/action_controller/failsafe.rb:26:in 'call'
/etc/sonarqube/web/WEB-INF/gems/gems/actionpack-2.3.15/lib/action_controller/dispatcher.rb:106:in 'call'
file:/etc/sonarqube/lib/server/jruby-rack-1.1.13.2.jar!/rack/adapter/rails.rb:34:in 'serve_rails'
file:/etc/sonarqube/lib/server/jruby-rack-1.1.13.2.jar!/rack/adapter/rails.rb:39:in 'call'
file:/etc/sonarqube/lib/server/jruby-rack-1.1.13.2.jar!/rack/handler/servlet.rb:22:in 'call'

Answer

JRuby is packaged within SonarQube. It conflicts with local installation of ruby.

Removing the environment variables GEM_PATH, GEM_HOME and RAILS_ENV when starting SonarQube fixes the issue as it hides the ruby installation. Command is unset GEM_PATH GEM_HOME RAILS_ENV.

Comments