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`