ArrayTuple resizing multiply the capacity by 4 instead of doubling and adding 1
See original GitHub issueQuestions
Version
3.9.x
Context
when initializing an ArrayTuple using the length constructor with 0 length, it would throw the indexoutofbound exception.
Do you have a reproducer?
the bug is easy to reproduce.
Tuple params = new ArrayTuple(0);
params.addInteger(1).addInteger(2);
Steps to reproduce
- just run the code above with vertx 3.9+. it is working well with 3.8.x
Extra
it seems on the line 60 in the file io\vertx\sqlclient\impl\ArrayTuple.java , the + operator is evaluated prior to the << operator due to higher precedence. when 0 argument is passed, it is still 0 after shift, and then the problem occurs.
public Tuple addValue(Object value) {
if (size >= values.length) {
Object[] copy = new Object[values.length << 1 + 1];
System.arraycopy(values, 0, copy, 0, values.length);
values = copy;
}
values[size++] = value;
return this;
}
also, when I tried to find the source code of 3.8.x, I noticed that the branch 3.8 was also changed by the merge. but the maven repo of 3.8.x remains the old implementation(ArrayTuple extending ArrayList). not sure if it is correct though. anyway, here is the commit
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (5 by maintainers)
Top Results From Across the Web
Multiplying using the Doubling Strategy - YouTube
https://www.mathswithmum.comLearn how to multiply by 4 and 8 easily by doubling and doubling again.
Read more >CSC300: Resizing Arrays and Ammortized Analysis
N = 0; } private void resize(int capacity) { double[] temp = new double[capacity]; for (int i = 0; i < N; i+=1)...
Read more >SilTools Developer's Guide
Chapter 1: Introduction to the SIL Language. SIL Language Overview. 1-1. SIL Compared to Pascal. 1-2. The SIL Programming Environment. 1-2.
Read more >vtkScaledSOADataArrayTemplate< ValueTypeT > Class ... - VTK
vtkScaledSOADataArrayTemplate is the counterpart of vtkSOADataArrayTemplate with a scaling factor. Each component is stored in a separate array. The Scale value ...
Read more >How to Use Halving and Doubling for Multiplication
The halving and doubling strategy for multiplication is one of the most fascinating multiplication strategies.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
thanks for reporting it should be fine now
On Wed, Jun 17, 2020 at 2:46 PM Ysc notifications@github.com wrote:
yes, it actually is a real case, but happening embarrassingly. Here is the code snippet we write in practice.
somehow this time, one of our team members, who has little knowledege of programming, changes new
ArrayTuple(1)
to newArrayTuple(0)
. I actually asked him why he was doing this, he said he thought it makes no difference since ArrayTuple could grow its capacity itself. sounds terrible, I know.anyway, that`s how it is found.