mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 14:54:52 +02:00
8199773: (bf) XXXBuffer:compareTo method is not working as expected
Reviewed-by: alanb
This commit is contained in:
parent
917c015610
commit
a2ea38d2c9
3 changed files with 52 additions and 49 deletions
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
@ -149,7 +149,7 @@ class StringCharBuffer // package-private
|
||||||
that, that.position(),
|
that, that.position(),
|
||||||
Math.min(this.remaining(), that.remaining()));
|
Math.min(this.remaining(), that.remaining()));
|
||||||
if (i >= 0) {
|
if (i >= 0) {
|
||||||
return Character.compare(this.get(this.position() + i), that.get(this.position() + i));
|
return Character.compare(this.get(this.position() + i), that.get(that.position() + i));
|
||||||
}
|
}
|
||||||
return this.remaining() - that.remaining();
|
return this.remaining() - that.remaining();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
@ -1337,7 +1337,7 @@ public abstract class $Type$Buffer
|
||||||
that, that.position(),
|
that, that.position(),
|
||||||
Math.min(this.remaining(), that.remaining()));
|
Math.min(this.remaining(), that.remaining()));
|
||||||
if (i >= 0) {
|
if (i >= 0) {
|
||||||
return compare(this.get(this.position() + i), that.get(this.position() + i));
|
return compare(this.get(this.position() + i), that.get(that.position() + i));
|
||||||
}
|
}
|
||||||
return this.remaining() - that.remaining();
|
return this.remaining() - that.remaining();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
@ -45,7 +45,7 @@ import java.util.stream.IntStream;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @test
|
* @test
|
||||||
* @bug 8193085
|
* @bug 8193085 8199773
|
||||||
* @summary tests for buffer equals and compare
|
* @summary tests for buffer equals and compare
|
||||||
* @run testng EqualsCompareTest
|
* @run testng EqualsCompareTest
|
||||||
*/
|
*/
|
||||||
|
@ -120,8 +120,9 @@ public class EqualsCompareTest {
|
||||||
abstract T construct(int length, ByteOrder bo);
|
abstract T construct(int length, ByteOrder bo);
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
T slice(T a, int from, int to) {
|
T slice(T a, int from, int to, boolean dupOtherwiseSlice) {
|
||||||
return (T) a.position(from).limit(to).slice();
|
a = (T) a.position(from).limit(to);
|
||||||
|
return (T) (dupOtherwiseSlice ? a.duplicate() : a.slice());
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
|
@ -607,6 +608,7 @@ public class EqualsCompareTest {
|
||||||
BiFunction<BT, Integer, B> bConstructor) {
|
BiFunction<BT, Integer, B> bConstructor) {
|
||||||
int n = arraySizeFor(bt.elementType);
|
int n = arraySizeFor(bt.elementType);
|
||||||
|
|
||||||
|
for (boolean dupOtherwiseSlice : new boolean[]{ false, true }) {
|
||||||
for (int s : ranges(0, n)) {
|
for (int s : ranges(0, n)) {
|
||||||
B a = aConstructor.apply(bt, s);
|
B a = aConstructor.apply(bt, s);
|
||||||
B b = bConstructor.apply(bt, s);
|
B b = bConstructor.apply(bt, s);
|
||||||
|
@ -616,7 +618,7 @@ public class EqualsCompareTest {
|
||||||
int aLength = aTo - aFrom;
|
int aLength = aTo - aFrom;
|
||||||
|
|
||||||
B as = aLength != s
|
B as = aLength != s
|
||||||
? bt.slice(a, aFrom, aTo)
|
? bt.slice(a, aFrom, aTo, dupOtherwiseSlice)
|
||||||
: a;
|
: a;
|
||||||
|
|
||||||
for (int bFrom : ranges(0, s)) {
|
for (int bFrom : ranges(0, s)) {
|
||||||
|
@ -624,7 +626,7 @@ public class EqualsCompareTest {
|
||||||
int bLength = bTo - bFrom;
|
int bLength = bTo - bFrom;
|
||||||
|
|
||||||
B bs = bLength != s
|
B bs = bLength != s
|
||||||
? bt.slice(b, bFrom, bTo)
|
? bt.slice(b, bFrom, bTo, dupOtherwiseSlice)
|
||||||
: b;
|
: b;
|
||||||
|
|
||||||
boolean eq = bt.pairWiseEquals(as, bs);
|
boolean eq = bt.pairWiseEquals(as, bs);
|
||||||
|
@ -647,7 +649,7 @@ public class EqualsCompareTest {
|
||||||
for (int i = aFrom; i < aTo; i++) {
|
for (int i = aFrom; i < aTo; i++) {
|
||||||
B c = aConstructor.apply(bt, a.capacity());
|
B c = aConstructor.apply(bt, a.capacity());
|
||||||
B cs = aLength != s
|
B cs = aLength != s
|
||||||
? bt.slice(c, aFrom, aTo)
|
? bt.slice(c, aFrom, aTo, dupOtherwiseSlice)
|
||||||
: c;
|
: c;
|
||||||
|
|
||||||
// Create common prefix with a length of i - aFrom
|
// Create common prefix with a length of i - aFrom
|
||||||
|
@ -665,6 +667,7 @@ public class EqualsCompareTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static int[] ranges(int from, int to) {
|
static int[] ranges(int from, int to) {
|
||||||
int width = to - from;
|
int width = to - from;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue