8354138: LinkedBlockingDeque allows us to exceed size with addAll() - #24538
8354138: LinkedBlockingDeque allows us to exceed size with addAll()#24538kabutz wants to merge 2 commits into
Conversation
…ling the super.addAll() method
|
👋 Welcome back kabutz! A progress list of the required criteria for merging this PR into |
|
❗ This change is not yet ready to be integrated. |
|
Hi @kabutz, I believe you can create issues on JBS (bugs.openjdk.org) directly without going thorough bugs.java.com - as an author in OpenJDK census, you have an account associated with your email, and you can log in to the JBS at https://id.openjdk.org/console/login?backUrl=https://bugs.openjdk.org and from there, you can create or edit issues or CSRs. |
|
Thanks @liach, I'm just not sure about all the fields in the OpenJDK census - will try do that next time. |
|
@kabutz This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration! |
|
These changes have been included in #24925 |
In LinkedBlockingDeque.addAll() we first build up the chain of nodes and then add that chain in bulk to the existing nodes. We count the nodes in "int n" and then whilst holding the lock, we check that we haven't exceeded the capacity with "if (count + n <= capacity)". However, if we pass in a collection that has more than Integer.MAX_VALUE items in it, then we can overflow n, making it negative. Since "count + n" is also negative, we can add the chain to our last item, and thus we end up with a LinkedBlockingDeque with more than Integer.MAX_VALUE of items and a negative size(). stream().count() gives the correct number of items.
This happens both via the bulk add constructor LinkedBlockingDeque(Collection) and when we call addAll(Collection) directly.
In Java 8, they didn't have the clever addAll() method, and thus it failed immediately.
Here is some test code:
Output is:
This has been submitted as a bug - internal review ID : 9078362.
Progress
Integration blocker
Issue
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/24538/head:pull/24538$ git checkout pull/24538Update a local copy of the PR:
$ git checkout pull/24538$ git pull https://git.openjdk.org/jdk.git pull/24538/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 24538View PR using the GUI difftool:
$ git pr show -t 24538Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/24538.diff
Using Webrev
Link to Webrev Comment