From 8c2efd011f5bcb36e14b2185f5b2caab29cae7e5 Mon Sep 17 00:00:00 2001 From: Koichi ITO Date: Wed, 31 Mar 2021 08:46:16 +0900 Subject: [PATCH] Workaround for `Style/RedundantBegin` when using JRuby 9.2 Workaround for https://github.com/jruby/jruby/issues/6642. This commits prevent the following error when using JRuby 9.2. ```console % ruby -v jruby 9.2.17.0 (2.5.8) 2021-03-29 84d363da97 Java HotSpot(TM) 64-Bit Server VM 25.271-b09 on 1.8.0_271-b09 +jit [darwin-x86_64] % bundle exec rake documentation_syntax_check [warn]: Syntax error in `lib/rubocop/cop/lint/shadowed_exception.rb`:(118,18): syntax error, unexpected keyword_rescue [warn]: ParserSyntaxError: syntax error in `lib/rubocop/cop/lint/shadowed_exception.rb`:(118,18): syntax error, unexpected keyword_rescue [warn]: Stack trace: /Users/koic/.rbenv/versions/jruby-9.2.17.0/lib/ruby/gems/shared/gems/yard-0.9.26/lib/yard/parser/ruby/ruby_parser.rb:601:in `on_parse_error' org/jruby/ext/ripper/RubyRipper.java:347:in `parse' /Users/koic/.rbenv/versions/jruby-9.2.17.0/lib/ruby/gems/shared/gems/yard-0.9.26/lib/yard/parser/ruby/ruby_parser.rb:56:in `parse' /Users/koic/.rbenv/versions/jruby-9.2.17.0/lib/ruby/gems/shared/gems/yard-0.9.26/lib/yard/parser/ruby/ruby_parser.rb:17:in `parse' /Users/koic/.rbenv/versions/jruby-9.2.17.0/lib/ruby/gems/shared/gems/yard-0.9.26/lib/yard/parser/source_parser.rb:442:in `parse' /Users/koic/.rbenv/versions/jruby-9.2.17.0/lib/ruby/gems/shared/gems/yard-0.9.26/lib/yard/parser/source_parser.rb:46:in `block in parse' Files: 569 Modules: 88 ( 13 undocumented) Classes: 531 ( 2 undocumented) Constants: 892 ( 879 undocumented) Attributes: 31 ( 0 undocumented) Methods: 1186 ( 1060 undocumented) 28.37% documented rake aborted! NoMethodError: undefined method `each' for nil:NilClass /Users/koic/src/github.com/rubocop/rubocop/Rakefile:105:in `block in /Users/koic/src/github.com/rubocop/rubocop/Rakefile' /Users/koic/src/github.com/rubocop/rubocop/lib/rubocop/cop/registry.rb:207:in `each' /Users/koic/src/github.com/rubocop/rubocop/Rakefile:96:in `block in
' /Users/koic/.rbenv/versions/jruby-9.2.17.0/bin/bundle:23:in `
' Tasks: TOP => documentation_syntax_check (See full trace by running task with --trace) ``` --- lib/rubocop/cop/lint/shadowed_exception.rb | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/rubocop/cop/lint/shadowed_exception.rb b/lib/rubocop/cop/lint/shadowed_exception.rb index 83fca3b1c57..00cdebd457b 100644 --- a/lib/rubocop/cop/lint/shadowed_exception.rb +++ b/lib/rubocop/cop/lint/shadowed_exception.rb @@ -111,12 +111,18 @@ def evaluate_exceptions(group) if rescued_exceptions.any? rescued_exceptions.each_with_object([]) do |exception, converted| - RuboCop::Util.silence_warnings do - # Avoid printing deprecation warnings about constants - converted << Kernel.const_get(exception.source) + # FIXME: Workaround `rubocop:disable` comment for JRuby. + # https://github.com/jruby/jruby/issues/6642 + # rubocop:disable Style/RedundantBegin + begin + RuboCop::Util.silence_warnings do + # Avoid printing deprecation warnings about constants + converted << Kernel.const_get(exception.source) + end + rescue NameError + converted << nil end - rescue NameError - converted << nil + # rubocop:enable Style/RedundantBegin end else # treat an empty `rescue` as `rescue StandardError`