Skip to content

Unhandled Java exception: org.jruby.RubyContinuation$Continuation #6507

@Confusion

Description

@Confusion

When running the following script

require 'parser/current'

code = "def main; CONSTANT = nil; end"

parser = Parser::CurrentRuby.new
buffer = Parser::Source::Buffer.new('code', source: code)
parser.parse(buffer)

as bin/jruby repro.rb, the script fails with:

Unhandled Java exception: org.jruby.RubyContinuation$Continuation
org.jruby.RubyContinuation$Continuation: null

The expected behavior for this way of using the parser gem is that the script silently ends. There are ways to get it to report parse failures (parser.diagnostics.consumer = ->(diag) {puts diag.render}), but those don't otherwise change the behavior.

This is using the whitequark/parser gem, 3.0.0.0. The issue was originally found using parser 2.7.2.0 on JRuby 9.2.13.0.

Further context

This issue is related to a combination of parser, racc and JRuby. Similar code is otherwise handled as expected:

$ bin/jruby -e 'def main; CONSTANT = nil; end'
SyntaxError: -e:1: dynamic constant assignment

With Parser::CurrentRuby.parse(code) instead of the Parser invocation in the reproduction:

$ bin/jruby repro.rb 
(string):2:3: error: dynamic constant assignment
(string):2:   CONSTANT = nil
(string):2:   ^~~~~~~~      
Parser::SyntaxError: dynamic constant assignment
           process at jruby/lib/ruby/gems/shared/gems/parser-3.0.0.0/lib/parser/diagnostic/engine.rb:72
        diagnostic at jruby/lib/ruby/gems/shared/gems/parser-3.0.0.0/lib/parser/builders/default.rb:2189
        assignable at jruby/lib/ruby/gems/shared/gems/parser-3.0.0.0/lib/parser/builders/default.rb:668
       _reduce_102 at jruby/lib/ruby/gems/shared/gems/parser-3.0.0.0/lib/parser/ruby25.rb:3958
  _racc_do_parse_c at com/headius/racc/Cparse.java:709
          do_parse at jruby/lib/ruby/stdlib/racc/parser.rb:264
             parse at jruby/lib/ruby/gems/shared/gems/parser-3.0.0.0/lib/parser/base.rb:190
             parse at jruby/lib/ruby/gems/shared/gems/parser-3.0.0.0/lib/parser/base.rb:33
            <main> at repro.rb:14

This bug is probably related to whitequark/parser#305, #4071, ruby/racc@68bafd3 and ruby/racc#91, via #6194.

However my takeaway from those issues and that commit is that this should not be able to happen, as current JRuby should be using racc-1.5+ since at least JRuby 9.1.12.0, which doesn't use RubyContinuation any more. Since it does happen, I wonder whether an old version of the racc cparse.java, possibly in compiled form, lingers in the JRuby codebase and is actually being used.

Further observations

Environment Information

$ bin/jruby -v
jruby 9.2.15.0-SNAPSHOT (2.5.7) 2020-12-25 69334b7b49 OpenJDK 64-Bit Server VM 11.0.9.1+1-Ubuntu-0ubuntu1.20.04 on 11.0.9.1+1-Ubuntu-0ubuntu1.20.04 +jit [linux-x86_64]

$ uname -a
Linux photon 5.4.0-59-generic #65-Ubuntu SMP Thu Dec 10 12:01:51 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions