Skip to content

JRuby crashes instead of reporting a syntax error in sequential rescues where the error variable wasn't defined for the first one #6761

@dee-see

Description

@dee-see

Excuse the messy title, hopefully the example make it clearer 😅

Environment Information

Provide at least:

  • JRuby version (jruby -v) and command line (flags, JRUBY_OPTS, etc): jruby 9.2.19.0 (2.5.8) 2021-06-15 55810c552b OpenJDK 64-Bit Server VM 11.0.12+7 on 11.0.12+7 +jit [linux-x86_64]
  • Operating system and platform (e.g. uname -a): Linux MYHOSTNAME 5.13.4-arch1-1 #1 SMP PREEMPT Tue, 20 Jul 2021 16:58:51 +0000 x86_64 GNU/Linux

Expected Behavior

Given this ruby file with a syntax error:

begin
  # no-op
rescue StandardError =>
  # nothing after =>, a variable name would be expected
  abort('error happened')
rescue StandardError => e
  # We need another rescue
end

This is a simplified case of a mistake I made in real code. I would expect a syntax error to be displayed when attempting to run this as I get with ruby 3.0.1p64 (2021-04-05 revision 0fb782ee38) [x86_64-linux]

$ ruby /tmp/crash.rb
/tmp/crash.rb:5: syntax error, unexpected '\n', expecting '.' or &. or :: or '['

The "expecting" part isn't totally right, but at least we're told what and where the error is.

Actual Behavior

$ jruby /tmp/crash.rb
Unhandled Java exception: java.lang.NegativeArraySizeException: -1
java.lang.NegativeArraySizeException: -1
              prepareMessage at org/jruby/lexer/yacc/SyntaxException.java:111
                      <init> at org/jruby/lexer/yacc/SyntaxException.java:96
               compile_error at org/jruby/lexer/yacc/RubyLexer.java:390
                     yyerror at org/jruby/parser/ParserSupport.java:1209
                     yyparse at org/jruby/parser/RubyParser.java:1659
                     yyparse at org/jruby/parser/RubyParser.java:1589
                       parse at org/jruby/parser/RubyParser.java:5744
                       parse at org/jruby/parser/Parser.java:133
                       parse at org/jruby/parser/Parser.java:108
          parseFileAndGetAST at org/jruby/Ruby.java:2527
  parseFileFromMainAndGetAST at org/jruby/Ruby.java:2520
           parseFileFromMain at org/jruby/Ruby.java:2504
               parseFromMain at org/jruby/Ruby.java:991
                 runFromMain at org/jruby/Ruby.java:937
               doRunFromMain at org/jruby/Main.java:400
                 internalRun at org/jruby/Main.java:292
                         run at org/jruby/Main.java:234
                        main at org/jruby/Main.java:206

This isn't blocking me or anything, but I figured I'd report anyway. Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions