Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Error running rubocop with JRuby 9.4.0.0 #7520

Closed
UweKubosch opened this issue Dec 12, 2022 · 5 comments
Closed

Error running rubocop with JRuby 9.4.0.0 #7520

UweKubosch opened this issue Dec 12, 2022 · 5 comments
Milestone

Comments

@UweKubosch
Copy link
Contributor

Environment Information

jruby 9.4.0.0 (3.1.0) 2022-11-23 95c0ec1 OpenJDK 64-Bit Server VM 17.0.5+8 on 17.0.5+8 +jit [x86_64-darwin]
Darwin messerschmitt 21.6.0 Darwin Kernel Version 21.6.0: Thu Sep 29 20:12:57 PDT 2022; root:xnu-8020.240.7~1/RELEASE_X86_64 x86_64
rubocop 1.40.0 (using Parser 3.1.3.0, rubocop-ast 1.24.0, running on jruby 3.1.0) [java]

Expected Behavior

Given a ruby file example.rb

class Example
  def foo
  rescue
    bar {}
  end
end

running

rubocop example.rb

should complete with some rubocop offenses. This works fine with JRuby 9.3.9.0 and Ruby 3.1.3:

Inspecting 1 file
C

Offenses:

example.rb:1:1: C: Style/Documentation: Missing top-level documentation comment for class Example.
class Example
^^^^^^^^^^^^^
example.rb:1:1: C: [Correctable] Style/FrozenStringLiteralComment: Missing frozen string literal comment.
class Example
^
example.rb:3:3: C: [Correctable] Style/RescueStandardError: Avoid rescuing without specifying an error class.
  rescue
  ^^^^^^

1 file inspected, 3 offenses detected, 2 offenses autocorrectable

Actual Behavior

With JRuby 9.4.0.0 there is an error:

For example_directory: Default configuration from ~/.gem/jruby/3.1.0/gems/rubocop-1.40.0/config/default.yml
Inspecting 1 file
Scanning example.rb
An error occurred while VariableForce cop was inspecting example.rb.
no receiver given
~/.gem/jruby/3.1.0/gems/rubocop-ast-1.24.0/lib/rubocop/ast/node/mixin/descendence.rb:106:in `block in visit_descendants'
~/.gem/jruby/3.1.0/gems/rubocop-ast-1.24.0/lib/rubocop/ast/node/mixin/descendence.rb:28:in `block in each_child_node'
org/jruby/RubyArray.java:1988:in `each'
~/.gem/jruby/3.1.0/gems/rubocop-ast-1.24.0/lib/rubocop/ast/node/mixin/descendence.rb:25:in `each_child_node'
~/.gem/jruby/3.1.0/gems/rubocop-ast-1.24.0/lib/rubocop/ast/node/mixin/descendence.rb:105:in `visit_descendants'
~/.gem/jruby/3.1.0/gems/rubocop-ast-1.24.0/lib/rubocop/ast/node/mixin/descendence.rb:107:in `block in visit_descendants'
~/.gem/jruby/3.1.0/gems/rubocop-ast-1.24.0/lib/rubocop/ast/node/mixin/descendence.rb:28:in `block in each_child_node'
org/jruby/RubyArray.java:1988:in `each'
~/.gem/jruby/3.1.0/gems/rubocop-ast-1.24.0/lib/rubocop/ast/node/mixin/descendence.rb:25:in `each_child_node'
~/.gem/jruby/3.1.0/gems/rubocop-ast-1.24.0/lib/rubocop/ast/node/mixin/descendence.rb:105:in `visit_descendants'
~/.gem/jruby/3.1.0/gems/rubocop-ast-1.24.0/lib/rubocop/ast/node/mixin/descendence.rb:60:in `each_descendant'
org/jruby/RubyEnumerator.java:397:in `each'
org/jruby/RubyEnumerable.java:1785:in `any?'
~/.gem/jruby/3.1.0/gems/rubocop-1.40.0/lib/rubocop/cop/variable_force.rb:252:in `block in process_rescue'
~/.gem/jruby/3.1.0/gems/rubocop-ast-1.24.0/lib/rubocop/ast/node/mixin/descendence.rb:28:in `block in each_child_node'
org/jruby/RubyArray.java:1988:in `each'
~/.gem/jruby/3.1.0/gems/rubocop-ast-1.24.0/lib/rubocop/ast/node/mixin/descendence.rb:25:in `each_child_node'
org/jruby/RubyEnumerator.java:397:in `each'
org/jruby/RubyEnumerable.java:1785:in `any?'
~/.gem/jruby/3.1.0/gems/rubocop-1.40.0/lib/rubocop/cop/variable_force.rb:251:in `process_rescue'
~/.gem/jruby/3.1.0/gems/rubocop-1.40.0/lib/rubocop/cop/variable_force.rb:86:in `process_node'
~/.gem/jruby/3.1.0/gems/rubocop-1.40.0/lib/rubocop/cop/variable_force.rb:103:in `block in process_children'
~/.gem/jruby/3.1.0/gems/rubocop-ast-1.24.0/lib/rubocop/ast/node/mixin/descendence.rb:28:in `block in each_child_node'
org/jruby/RubyArray.java:1988:in `each'
~/.gem/jruby/3.1.0/gems/rubocop-ast-1.24.0/lib/rubocop/ast/node/mixin/descendence.rb:25:in `each_child_node'
~/.gem/jruby/3.1.0/gems/rubocop-1.40.0/lib/rubocop/cop/variable_force.rb:100:in `process_children'
~/.gem/jruby/3.1.0/gems/rubocop-1.40.0/lib/rubocop/cop/variable_force.rb:95:in `inspect_variables_in_scope'
~/.gem/jruby/3.1.0/gems/rubocop-1.40.0/lib/rubocop/cop/variable_force.rb:276:in `process_scope'
~/.gem/jruby/3.1.0/gems/rubocop-1.40.0/lib/rubocop/cop/variable_force.rb:86:in `process_node'
~/.gem/jruby/3.1.0/gems/rubocop-1.40.0/lib/rubocop/cop/variable_force.rb:103:in `block in process_children'
~/.gem/jruby/3.1.0/gems/rubocop-ast-1.24.0/lib/rubocop/ast/node/mixin/descendence.rb:28:in `block in each_child_node'
org/jruby/RubyArray.java:1988:in `each'
~/.gem/jruby/3.1.0/gems/rubocop-ast-1.24.0/lib/rubocop/ast/node/mixin/descendence.rb:25:in `each_child_node'
~/.gem/jruby/3.1.0/gems/rubocop-1.40.0/lib/rubocop/cop/variable_force.rb:100:in `process_children'
~/.gem/jruby/3.1.0/gems/rubocop-1.40.0/lib/rubocop/cop/variable_force.rb:95:in `inspect_variables_in_scope'
~/.gem/jruby/3.1.0/gems/rubocop-1.40.0/lib/rubocop/cop/variable_force.rb:276:in `process_scope'
~/.gem/jruby/3.1.0/gems/rubocop-1.40.0/lib/rubocop/cop/variable_force.rb:86:in `process_node'
~/.gem/jruby/3.1.0/gems/rubocop-1.40.0/lib/rubocop/cop/variable_force.rb:80:in `investigate'
~/.gem/jruby/3.1.0/gems/rubocop-1.40.0/lib/rubocop/cop/commissioner.rb:153:in `block in invoke'
~/.gem/jruby/3.1.0/gems/rubocop-1.40.0/lib/rubocop/cop/commissioner.rb:160:in `with_cop_error_handling'
~/.gem/jruby/3.1.0/gems/rubocop-1.40.0/lib/rubocop/cop/commissioner.rb:153:in `block in invoke'
org/jruby/RubyArray.java:1988:in `each'
~/.gem/jruby/3.1.0/gems/rubocop-1.40.0/lib/rubocop/cop/commissioner.rb:153:in `invoke'
~/.gem/jruby/3.1.0/gems/rubocop-1.40.0/lib/rubocop/cop/commissioner.rb:85:in `investigate'
~/.gem/jruby/3.1.0/gems/rubocop-1.40.0/lib/rubocop/cop/team.rb:154:in `investigate_partial'
~/.gem/jruby/3.1.0/gems/rubocop-1.40.0/lib/rubocop/cop/team.rb:82:in `investigate'
~/.gem/jruby/3.1.0/gems/rubocop-1.40.0/lib/rubocop/runner.rb:315:in `inspect_file'
~/.gem/jruby/3.1.0/gems/rubocop-1.40.0/lib/rubocop/runner.rb:259:in `block in do_inspection_loop'
~/.gem/jruby/3.1.0/gems/rubocop-1.40.0/lib/rubocop/runner.rb:293:in `block in iterate_until_no_changes'
org/jruby/RubyKernel.java:1586:in `loop'
~/.gem/jruby/3.1.0/gems/rubocop-1.40.0/lib/rubocop/runner.rb:286:in `iterate_until_no_changes'
~/.gem/jruby/3.1.0/gems/rubocop-1.40.0/lib/rubocop/runner.rb:255:in `do_inspection_loop'
~/.gem/jruby/3.1.0/gems/rubocop-1.40.0/lib/rubocop/runner.rb:138:in `block in file_offenses'
~/.gem/jruby/3.1.0/gems/rubocop-1.40.0/lib/rubocop/runner.rb:163:in `file_offense_cache'
~/.gem/jruby/3.1.0/gems/rubocop-1.40.0/lib/rubocop/runner.rb:137:in `file_offenses'
~/.gem/jruby/3.1.0/gems/rubocop-1.40.0/lib/rubocop/runner.rb:128:in `process_file'
~/.gem/jruby/3.1.0/gems/rubocop-1.40.0/lib/rubocop/runner.rb:109:in `block in each_inspected_file'
org/jruby/RubyArray.java:1988:in `each'
org/jruby/RubyEnumerable.java:1099:in `inject'
~/.gem/jruby/3.1.0/gems/rubocop-1.40.0/lib/rubocop/runner.rb:108:in `each_inspected_file'
~/.gem/jruby/3.1.0/gems/rubocop-1.40.0/lib/rubocop/runner.rb:94:in `inspect_files'
~/.gem/jruby/3.1.0/gems/rubocop-1.40.0/lib/rubocop/runner.rb:47:in `run'
~/.gem/jruby/3.1.0/gems/rubocop-1.40.0/lib/rubocop/cli/command/execute_runner.rb:26:in `block in execute_runner'
~/.gem/jruby/3.1.0/gems/rubocop-1.40.0/lib/rubocop/cli/command/execute_runner.rb:52:in `with_redirect'
~/.gem/jruby/3.1.0/gems/rubocop-1.40.0/lib/rubocop/cli/command/execute_runner.rb:25:in `execute_runner'
~/.gem/jruby/3.1.0/gems/rubocop-1.40.0/lib/rubocop/cli/command/execute_runner.rb:17:in `run'
~/.gem/jruby/3.1.0/gems/rubocop-1.40.0/lib/rubocop/cli/command.rb:11:in `run'
~/.gem/jruby/3.1.0/gems/rubocop-1.40.0/lib/rubocop/cli/environment.rb:18:in `run'
~/.gem/jruby/3.1.0/gems/rubocop-1.40.0/lib/rubocop/cli.rb:72:in `run_command'
~/.gem/jruby/3.1.0/gems/rubocop-1.40.0/lib/rubocop/cli.rb:79:in `execute_runners'
~/.gem/jruby/3.1.0/gems/rubocop-1.40.0/lib/rubocop/cli.rb:48:in `run'
~/.gem/jruby/3.1.0/gems/rubocop-1.40.0/exe/rubocop:19:in `block in <main>'
~/.rubies/jruby-9.4.0.0/lib/ruby/stdlib/benchmark.rb:311:in `realtime'
~/.gem/jruby/3.1.0/gems/rubocop-1.40.0/exe/rubocop:19:in `<main>'
org/jruby/RubyKernel.java:1091:in `load'
~/.gem/jruby/3.1.0/bin/rubocop:25:in `<main>'
C

Offenses:

example.rb:1:1: C: Style/Documentation: Missing top-level documentation comment for class Example.
class Example
^^^^^^^^^^^^^
example.rb:1:1: C: [Correctable] Style/FrozenStringLiteralComment: Missing frozen string literal comment.
class Example
^
example.rb:3:3: C: [Correctable] Style/RescueStandardError: Avoid rescuing without specifying an error class.
  rescue
  ^^^^^^

1 file inspected, 3 offenses detected, 2 offenses autocorrectable

1 error occurred:
An error occurred while VariableForce cop was inspecting example.rb.
Errors are usually caused by RuboCop bugs.
Please, report your problems to RuboCop's issue tracker.
https://github.com/rubocop/rubocop/issues

Mention the following information in the issue report:
1.40.0 (using Parser 3.1.3.0, rubocop-ast 1.24.0, running on jruby 3.1.0) [java]
@UweKubosch
Copy link
Contributor Author

This has been reported earlier as rubocop/rubocop#11214

@headius
Copy link
Member

headius commented Dec 13, 2022

Looking into it now!

@headius
Copy link
Member

headius commented Dec 13, 2022

The issue probably stems from this code in variable_force.rb and the symbol proc created at this point gets damaged further down the call stack somehow.

      def process_rescue(node)
        resbody_nodes = node.each_child_node(:resbody)

        contain_retry = resbody_nodes.any? do |resbody_node|
          resbody_node.each_descendant.any?(&:retry_type?)
        end

        # Treat begin..rescue..end with retry as a loop.
        process_loop(node) if contain_retry
      end

@headius
Copy link
Member

headius commented Dec 13, 2022

This appears to work correctly on master (9.4.1):

$ jruby -v -S rubocop blah.rb
jruby 9.4.1.0-SNAPSHOT (3.1.0) 2022-12-13 8f961780ab OpenJDK 64-Bit Server VM 19.0.1+10 on 19.0.1+10 +jit [arm64-darwin]
/Users/headius/work/jruby/lib/ruby/stdlib/ostruct.rb:467: warning: OpenStruct#public_send accesses caller method's state and should not be aliased
/Users/headius/work/jruby/lib/ruby/stdlib/ostruct.rb:467: warning: OpenStruct#method accesses caller method's state and should not be aliased
Inspecting 1 file
C

Offenses:

blah.rb:1:1: C: Style/Documentation: Missing top-level documentation comment for class Example.
class Example
^^^^^^^^^^^^^
blah.rb:1:1: C: [Correctable] Style/FrozenStringLiteralComment: Missing frozen string literal comment.
class Example
^
blah.rb:3:3: C: [Correctable] Style/RescueStandardError: Avoid rescuing without specifying an error class.
  rescue
  ^^^^^^

1 file inspected, 3 offenses detected, 2 offenses autocorrectable

Same result with forced compilation and indy enabled. @enebo Perhaps something you fixed recently?

@enebo enebo added this to the JRuby 9.4.1.0 milestone Dec 13, 2022
@enebo
Copy link
Member

enebo commented Dec 13, 2022

There was another issue reported against rubocop but this looks different. A bunch of things have been fixed (this could be an enumerable fix, kwarg fixes or even one of several ripper fixes) in the last week and I do not want to bisect what fixed this issue but it appears to be fixed at least.

@enebo enebo closed this as completed Dec 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants