Fix NoMethodError in Gem.try_activate when activation conflicts occur#9404
Fix NoMethodError in Gem.try_activate when activation conflicts occur#9404
Conversation
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>
There was a problem hiding this comment.
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.namebefore reassigningspecinside theGem.try_activateconflict-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.
|
@Edouard-chin Could you look this? |
|
I've tested this and it fixed the Redmine issue. |
|
@jeremyevans Thanks! |
Edouard-chin
left a comment
There was a problem hiding this comment.
🤦 Thanks for the fix !
|
@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. |
Fix NoMethodError in Gem.try_activate when activation conflicts occur (cherry picked from commit 0b7b83c)
Fix NoMethodError in Gem.try_activate when activation conflicts occur (cherry picked from commit 0b7b83c)
What was the end-user or developer problem that led to this PR?
When
find_unloaded_by_pathreturns nil, the subsequentspec.namecall raises NoMethodError becausespechas been overwritten. Save the gem name before reassigningspec.Fixes https://bugs.ruby-lang.org/issues/21954
Make sure the following tasks are checked