ChrisAHolland opened a new pull request, #15507:
URL: https://github.com/apache/kafka/pull/15507

   I noticed that were were a few implementation quirks with the implementation 
of `BoundedList.java` that could potentially lead to bugs if used improperly.
   
   1. A constructor like method with signature `newArrayBacked(int maxLength, 
int initialCapacity)` took in two integers, one for the maximum length of the 
`BoundedList`, and a second for the initial capacity of the underlying 
`ArrayList`. This seems like a flaw to me because when ArrayLists resize it is 
a O(n) operation, so if the initial capacity was "under-provisioned" compared 
to the maximum capacity, many resizing operations could take place as this list 
grows, which is not good for performance.
   
   Fix: Remove `newArrayBacked(int maxLength, int initialCapacity)` and use the 
new constructor instead (mentioned below).
   
   2. The public constructor had a signature of `public BoundedList(int 
maxLength, List<E> underlying)`. This is problematic because the the 
constructor created the `BoundedList` using a reference to `underlying`, not a 
copy of it; therefore, a user could add elements to `underlying` instead of 
their newly instantiated `BoundedList` and force the `BoundedList` to be larger 
than its maxLength`.
   
   Fix: Change the constructor to have signature `public BoundedList(int 
maxLength)`. I noticed that passing in a "original list" was only used in unit 
tests, never in the source code, but I felt that made the unit tests confusing. 
If this use case is ever needed, it can be added in again later on.
   
   3. Remaining changes involve updating the usages of `BoundedList` and 
cleaning up the unit tests.
   
   ### Committer Checklist (excluded from commit message)
   - [ ] Verify design and implementation 
   - [ ] Verify test coverage and CI build status
   - [ ] Verify documentation (including upgrade notes)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to