fix: return new BitList instance from emptyList() to prevent shared mutable state#16169
Open
daguimu wants to merge 1 commit intoapache:3.3from
Open
fix: return new BitList instance from emptyList() to prevent shared mutable state#16169daguimu wants to merge 1 commit intoapache:3.3from
daguimu wants to merge 1 commit intoapache:3.3from
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## 3.3 #16169 +/- ##
============================================
+ Coverage 60.81% 60.83% +0.02%
+ Complexity 11765 11752 -13
============================================
Files 1953 1953
Lines 89118 89117 -1
Branches 13444 13444
============================================
+ Hits 54197 54217 +20
+ Misses 29364 29347 -17
+ Partials 5557 5553 -4
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
…utable state BitList.emptyList() previously returned a shared static singleton instance. Since BitList is mutable, modifications to one caller's "empty" list would contaminate all other callers. This caused cross-interface invoker leakage in AbstractDirectory, leading to NoSuchMethodError when traffic was routed to instances of a previous interface. The fix returns a new BitList instance on each call, consistent with how mutable collections should behave. Fixes apache#16131
711cfb3 to
c862f97
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
BitList.emptyList()returns a shared static singleton instance. SinceBitListis mutable (supportsadd(),addToTailList(),and(), etc.), any caller that modifies the returned "empty" list inadvertently mutates the singleton, contaminating all subsequent callers.In
AbstractDirectory, theinvokersfield is initialized withBitList.emptyList(). When the first interface's invokers are added, they pollute the shared singleton. When a second interface later callsBitList.emptyList(), it receives a list already containing the first interface's invokers, causing traffic to be routed to the wrong instances and resulting inNoSuchMethodError.Root Cause
Fix
Return a new
BitListinstance on each call toemptyList(), consistent with how mutable collections should behave:Tests Added
testEmptyListReturnsIndependentInstances— Verifies each call returns a distinct objecttestEmptyListMutationDoesNotAffectOtherEmptyList— Reproduces the exact bug: adding elements to one empty list must not affect another (the core scenario from [Bug] The traffic will be routed to instances of previous interface, which causes no such method error #16131)testEmptyListTailListMutationDoesNotAffectOtherEmptyList— Verifies tail list mutations are also isolatedtestEmptyListIsInitiallyEmpty— Confirms the returned list starts truly emptyAll 26 tests in
BitListTestpass.Impact
BitList, just a fresh instance==) checks exist againstBitList.emptyList()in the codebaseNoSuchMethodErrorFixes #16131