Skip to content

Commit

Permalink
Workaround for Style/RedundantBegin when using JRuby 9.2
Browse files Browse the repository at this point in the history
Workaround for jruby/jruby#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
<main>'
/Users/koic/.rbenv/versions/jruby-9.2.17.0/bin/bundle:23:in `<main>'
Tasks: TOP => documentation_syntax_check
(See full trace by running task with --trace)
```
  • Loading branch information
koic authored and bbatsov committed Apr 5, 2021
1 parent 38d5b03 commit 1533ece
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions lib/rubocop/cop/lint/shadowed_exception.rb
Expand Up @@ -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`
Expand Down

0 comments on commit 1533ece

Please sign in to comment.