Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Ripper error when using Ruby 2.5's rescue inside do/end blocks without begin syntax #6642

Closed
koic opened this issue Mar 31, 2021 · 2 comments
Milestone

Comments

@koic
Copy link

koic commented Mar 31, 2021

Environment Information

Provide at least:

  • JRuby version (jruby -v) and command line (flags, JRUBY_OPTS, etc)
% jruby -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]
  • Operating system and platform (e.g. uname -a)
% uname -a
Darwin atelier.local 19.6.0 Darwin Kernel Version 19.6.0: Mon Aug 31 22:12:52 PDT 2020; root:xnu-6153.141.2~1/RELEASE_X86_64 x86_64

Expected Behavior

The following is an example:

# example.rb
require 'ripper'

class RipperParser < Ripper
  def on_parse_error(message)
    raise message
  end
end

RipperParser.new(<<~RUBY).parse
  foo do
    bar do
    end
  rescue NameError
    converted << nil
  end
RUBY

This is behavior of MRI 2.5.8.

% ruby -v
ruby 2.5.8p224 (2020-03-31 revision 67882) [x86_64-darwin17]
% ruby example.rb

No errors.

Actual Behavior

This is behavior of JRuby 9.2.17.0.

% 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]
% ruby example.rb
RuntimeError: syntax error, unexpected keyword_rescue

  on_parse_error at example.rb:6
           parse at org/jruby/ext/ripper/RubyRipper.java:347
          <main> at example.rb:10

Unexpectedly, JRuby 9.2.17.0 raises the RuntimeError.

I encountered this issue in YARD on which RuboCop depends.
rubocop/rubocop#9648

koic added a commit to koic/rubocop that referenced this issue Mar 31, 2021
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)
```
bbatsov pushed a commit to rubocop/rubocop that referenced this issue Apr 5, 2021
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)
```
@koic
Copy link
Author

koic commented Oct 30, 2021

It still reproduces in JRuby 9.3.0.0.

% ruby -v
ruby 3.0.2p107 (2021-07-07 revision 0db68f0233) [x86_64-darwin19]
% ruby example.rb # no errors.

% ruby -v
jruby 9.3.0.0 (2.6.8) 2021-09-17 85c20e780f Java HotSpot(TM) 64-Bit Server VM 25.271-b09 on 1.8.0_271-b09 +jit 
% ruby example.rb
RuntimeError: syntax error, unexpected rescue

  on_parse_error at example.rb:6
           parse at org/jruby/ext/ripper/RubyRipper.java:342
          <main> at example.rb:10

koic added a commit to koic/rubocop that referenced this issue Jun 3, 2023
## Summary

Revert rubocop@1533ece

Current RuboCop (1.52) requires Ruby 2.7+ and JRuby 9.4+.
So JRuby 9.2 has been dropped from runtime version.

## Additional Information

jruby/jruby#6642 has been resolved in JRuby 9.4:

```ruby
# example.rb
require 'ripper'

class RipperParser < Ripper
  def on_parse_error(message)
    raise message
  end
end

RipperParser.new(<<~RUBY).parse
  foo do
    bar do
  end
rescue NameError
  converted << nil
end
RUBY
```

```console
$ ruby -v
jruby 9.4.2.0 (3.1.0) 2023-03-08 90d2913fda Java HotSpot(TM) 64-Bit Server VM 25.271-b09 on 1.8.0_271-b09 +jit [x86_64-darwin]
$ ruby example.rb # No errors
```
@koic
Copy link
Author

koic commented Jun 3, 2023

This issue has been resolved in JRuby 9.4:

$ ruby -v
jruby 9.4.2.0 (3.1.0) 2023-03-08 90d2913fda Java HotSpot(TM) 64-Bit Server VM 25.271-b09 on 1.8.0_271-b09 +jit [x86_64-darwin]
$ ruby example.rb # No errors

Thank you!

@koic koic closed this as completed Jun 3, 2023
bbatsov pushed a commit to rubocop/rubocop that referenced this issue Jun 4, 2023
## Summary

Revert 1533ece

Current RuboCop (1.52) requires Ruby 2.7+ and JRuby 9.4+.
So JRuby 9.2 has been dropped from runtime version.

## Additional Information

jruby/jruby#6642 has been resolved in JRuby 9.4:

```ruby
# example.rb
require 'ripper'

class RipperParser < Ripper
  def on_parse_error(message)
    raise message
  end
end

RipperParser.new(<<~RUBY).parse
  foo do
    bar do
  end
rescue NameError
  converted << nil
end
RUBY
```

```console
$ ruby -v
jruby 9.4.2.0 (3.1.0) 2023-03-08 90d2913fda Java HotSpot(TM) 64-Bit Server VM 25.271-b09 on 1.8.0_271-b09 +jit [x86_64-darwin]
$ ruby example.rb # No errors
```
@enebo enebo added this to the JRuby 9.4.2.0 milestone Jun 5, 2023
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants