Skip to content

Fix alias_module_function on JRuby - #327

Merged
trans merged 1 commit into
mainfrom
claude/github-connector-capabilities-4qcre6
Sep 27, 2026
Merged

trans merged 1 commit into
mainfrom
claude/github-connector-capabilities-4qcre6

Conversation

@trans

@trans trans commented Sep 27, 2026

Copy link
Copy Markdown
Member

Fixes the only failing test in the JRuby CI job (test/standard/test_uri.rb: private method 'hash_to_query' called for module URI), which has been red on main since at least #325.

Cause

  • URI.hash_to_query is defined with alias_module_function :hash_to_query, :query, which calls alias_method and then module_function(new).
  • On JRuby 10.1, the singleton method module_function(name) creates is public, but it turns private as soon as it's aliased again. CRuby keeps it public.
  • Lemon aliases every method under test to wrap it for coverage, then aliases it back afterwards. So once the URI.hash_to_query test ran, the method was private, and the later Hash#to_uri test failed.

Normal callers don't hit this unless they re-alias the method, but anything that wraps methods the way Lemon does will.

Fix

alias_module_function now aliases the singleton method directly:

def alias_module_function(new, old)
  alias_method(new, old)
  return module_function(new) unless singleton_class.method_defined?(old)
  singleton_class.send(:alias_method, new, old)
end

That matches the documented contract ("alias a module function so the alias is also a module function"), and the result stays public on JRuby. If old isn't a module function, it falls back to module_function(new) exactly as before.

Testing

I reproduced this locally with JRuby 10.1.2.0, the version CI uses.

  • A new test re-aliases the singleton method. It fails on JRuby without this fix and passes with it. The existing test now also checks that the instance alias is private.
  • Full suite on JRuby 10.1.2: 1,253 tests, 1,249 passing, 4 pending, 0 errors. Previously 1 error.
  • Full suite on CRuby 3.3: the same, 0 errors.
  • The fallback path (aliasing a plain instance method) behaves the same as before on both Rubies.

🤖 Generated with Claude Code

https://claude.ai/code/session_01E2Njj4j1r9twkVcXsMySLW


Generated by Claude Code

On JRuby 10.1, a singleton method created by module_function(name) turns
private when it is aliased again. Lemon aliases each method under test to
wrap and then restore it, so after the URI.hash_to_query test ran,
Hash#to_uri failed with "private method 'hash_to_query' called for module
URI". This was the only failing test in the JRuby CI job.

alias_module_function now aliases the singleton method directly, which
stays public on JRuby. If the old method isn't a module function, it
falls back to module_function as before.

Adds a test that re-aliases the new singleton method; it fails on JRuby
without this fix.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01E2Njj4j1r9twkVcXsMySLW
@trans
trans merged commit 5f72f8b into main Sep 27, 2026
14 checks passed
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

Successfully merging this pull request may close these issues.

2 participants