@@ -117,11 +117,11 @@ private void grow(int size) {
117117 T [] temp = (T []) new Object [growSize ];
118118 // Since the array can wrap around, make sure you grab the first chunk
119119 int adjLast = lastIndex % array .length ;
120- if (adjLast < firstIndex ) {
121- System .arraycopy (array , 0 , temp , array .length -adjLast , adjLast + 1 );
120+ if (adjLast > 0 && adjLast <= firstIndex ) {
121+ System .arraycopy (array , 0 , temp , array .length -adjLast , adjLast );
122122 }
123123 // Copy the remaining
124- System .arraycopy (array , firstIndex , temp , 0 , array .length - firstIndex );
124+ System .arraycopy (array , firstIndex , temp , 0 , array .length - firstIndex );
125125 array = null ;
126126 array = temp ;
127127 lastIndex = (lastIndex - firstIndex );
@@ -134,9 +134,9 @@ private void shrink() {
134134 T [] temp = (T []) new Object [shrinkSize ];
135135 // Since the array can wrap around, make sure you grab the first chunk
136136 int adjLast = lastIndex % array .length ;
137- int endIndex = (lastIndex >array .length )? array .length : lastIndex ;
137+ int endIndex = (lastIndex >array .length ) ? array .length : lastIndex ;
138138 if (adjLast <= firstIndex ) {
139- System .arraycopy (array , 0 , temp , array .length - firstIndex , adjLast );
139+ System .arraycopy (array , 0 , temp , array .length - firstIndex , adjLast );
140140 }
141141 // Copy the remaining
142142 System .arraycopy (array , firstIndex , temp , 0 , endIndex -firstIndex );
0 commit comments