Skip to content

Signal.signame raises instead of returning nil for unknown values #10094

Open

Description

@headius

Additional discovery after fixing #10080:

One more difference I found since, which isn't Windows's alone: for a number with no signal, JRuby's Signal.signame raises where CRuby's returns nil. On JRuby 10.1.2.0, on macOS:

$ jruby -e 'p Signal.signame(99)'
ArgumentError: invalid signal number: 99
  signame at org/jruby/RubySignal.java:210
   <main> at -e:1
$ ruby -e 'p Signal.signame(99)'
nil

CRuby's sig_signame returns nil for a number signo2signm has no name for:

https://github.com/ruby/ruby/blob/06b18f11f4b0078e2683c661e7762fff7c04636c/signal.c#L310-L315

JRuby's raises an ArgumentError there, on every platform (0 aside, which is "EXIT"):

@JRubyMethod(meta = true)
public static IRubyObject signame(ThreadContext context, final IRubyObject recv, IRubyObject rubySig) {
long sig = toInt(context, rubySig);
String signame = signo2signm(sig);
if (signame == null) {
if (sig == 0) return newString(context, "EXIT");
throw argumentError(context, "invalid signal number: " + rubySig);
}
return newString(context, signame);
}

So code written for CRuby that checks for nil (to name a signal by its number instead, say) gets an exception on JRuby. Returning nil there would match CRuby, and on Windows, Signal.signame(9) would then return nil rather than raise even before KILL is mapped.

Originally posted by @sferik in #10080

Activity

  1. added this to the JRuby 10.1.4.0 milestone on Nov 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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