Skip to content

Commit 174148a

Browse files
committed
Fix ArrayCodec's behaviour for preffix and identical arrays
1 parent 78ed79f commit 174148a

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

test/lib/jdk/test/lib/format/ArrayCodec.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -301,10 +301,11 @@ public int getElementLength() {
301301
* Finds and returns the first mismatch index in another codec
302302
*
303303
* @param another a codec mismatch with whom is to be found
304-
* @return the first mismatched element's index
304+
* @return the first mismatched element's index or -1 if arrays are identical
305305
*/
306306
public int findMismatchIndex(ArrayCodec<E> another) {
307-
for (int result = 0; (source.size() > result) && (another.source.size() > result); result++) {
307+
int result = 0;
308+
while ((source.size() > result) && (another.source.size() > result)) {
308309
Object first = source.get(result);
309310
Object second = another.source.get(result);
310311

@@ -320,9 +321,12 @@ public int findMismatchIndex(ArrayCodec<E> another) {
320321
return result;
321322
}
322323

324+
result++;
323325
}
324326

325-
return 0;
327+
return source.size() != another.source.size()
328+
? result // Lengths are different, but the shorter arrays is a preffix to the longer array.
329+
: -1; // Arrays are identical, there's no mismatch index
326330
}
327331

328332
/**

0 commit comments

Comments
 (0)