Skip to content

Fix NoMethodError in Gem.try_activate when activation conflicts occur#9404

Merged
hsbt merged 1 commit intomasterfrom
fix-bug-21954
Mar 17, 2026
Merged

Fix NoMethodError in Gem.try_activate when activation conflicts occur#9404
hsbt merged 1 commit intomasterfrom
fix-bug-21954

Conversation

@hsbt
Copy link
Copy Markdown
Member

@hsbt hsbt commented Mar 17, 2026

What was the end-user or developer problem that led to this PR?

When find_unloaded_by_path returns nil, the subsequent spec.name call raises NoMethodError because spec has been overwritten. Save the gem name before reassigning spec.

Fixes https://bugs.ruby-lang.org/issues/21954

Make sure the following tasks are checked

When `find_unloaded_by_path` returns nil, the subsequent
`spec.name` call raises NoMethodError because `spec` has been
overwritten. Save the gem name before reassigning `spec`.

Fixes https://bugs.ruby-lang.org/issues/21954

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings March 17, 2026 03:51
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a NoMethodError in Gem.try_activate when an activation conflict occurs and find_unloaded_by_path returns nil, by preserving the originally selected spec’s name before reassigning spec.

Changes:

  • Preserve spec.name before reassigning spec inside the Gem.try_activate conflict-handling rescue path.
  • Add a regression test covering the activation-conflict scenario that previously triggered the NoMethodError.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
lib/rubygems.rb Prevents NoMethodError by avoiding dereferencing spec after it may have been set to nil during conflict recovery.
test/rubygems/test_gem.rb Adds a regression test ensuring Gem.try_activate does not raise when an older version is activated and a newer-only file is requested.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

@hsbt
Copy link
Copy Markdown
Member Author

hsbt commented Mar 17, 2026

@Edouard-chin Could you look this?

@hsbt hsbt self-assigned this Mar 17, 2026
@jeremyevans
Copy link
Copy Markdown
Contributor

I've tested this and it fixed the Redmine issue.

@hsbt
Copy link
Copy Markdown
Member Author

hsbt commented Mar 17, 2026

@jeremyevans Thanks!

@hsbt hsbt merged commit 0b7b83c into master Mar 17, 2026
115 of 117 checks passed
@hsbt hsbt deleted the fix-bug-21954 branch March 17, 2026 06:55
Copy link
Copy Markdown
Collaborator

@Edouard-chin Edouard-chin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤦 Thanks for the fix !

@hsbt
Copy link
Copy Markdown
Member Author

hsbt commented Mar 25, 2026

@jeremyevans I missed to backport this to 4.0.9 release. I will do that for 4.0.10 at 8th, April. Sorry to your inconvenience.

hsbt added a commit that referenced this pull request Apr 7, 2026
Fix NoMethodError in Gem.try_activate when activation conflicts occur

(cherry picked from commit 0b7b83c)
hsbt added a commit that referenced this pull request Apr 7, 2026
Fix NoMethodError in Gem.try_activate when activation conflicts occur

(cherry picked from commit 0b7b83c)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants