mirror of
https://github.com/openjdk/jdk.git
synced 2026-04-12 07:58:43 +00:00
8028321: Fix for String.split() empty input sequence/JDK-6559590 triggers regression
To undo the change for 6559590 Reviewed-by: darcy
This commit is contained in:
parent
fadfc31bec
commit
dc1dba10e7
@ -2235,8 +2235,7 @@ public final class String
|
||||
* expression or is terminated by the end of the string. The substrings in
|
||||
* the array are in the order in which they occur in this string. If the
|
||||
* expression does not match any part of the input then the resulting array
|
||||
* has just one element, namely this string. A zero-length input sequence
|
||||
* always results zero-length resulting array.
|
||||
* has just one element, namely this string.
|
||||
*
|
||||
* <p> When there is a positive-width match at the beginning of this
|
||||
* string then an empty leading substring is included at the beginning
|
||||
@ -2331,8 +2330,6 @@ public final class String
|
||||
(ch < Character.MIN_HIGH_SURROGATE ||
|
||||
ch > Character.MAX_LOW_SURROGATE))
|
||||
{
|
||||
if (value.length == 0)
|
||||
return new String[0];
|
||||
int off = 0;
|
||||
int next = 0;
|
||||
boolean limited = limit > 0;
|
||||
|
||||
@ -1144,8 +1144,7 @@ public final class Pattern
|
||||
* substrings in the array are in the order in which they occur in the
|
||||
* input. If this pattern does not match any subsequence of the input then
|
||||
* the resulting array has just one element, namely the input sequence in
|
||||
* string form. A zero-length input sequence always results zero-length
|
||||
* resulting array.
|
||||
* string form.
|
||||
*
|
||||
* <p> When there is a positive-width match at the beginning of the input
|
||||
* sequence then an empty leading substring is included at the beginning
|
||||
@ -1201,8 +1200,6 @@ public final class Pattern
|
||||
* around matches of this pattern
|
||||
*/
|
||||
public String[] split(CharSequence input, int limit) {
|
||||
if (input.length() == 0)
|
||||
return new String[0];
|
||||
int index = 0;
|
||||
boolean matchLimited = limit > 0;
|
||||
ArrayList<String> matchList = new ArrayList<>();
|
||||
@ -5767,15 +5764,13 @@ NEXT: while (i <= last) {
|
||||
* input sequence that is terminated by another subsequence that matches
|
||||
* this pattern or is terminated by the end of the input sequence. The
|
||||
* substrings in the stream are in the order in which they occur in the
|
||||
* input. Trailing empty strings will be discarded and not encountered in
|
||||
* input. Trailing empty strings will be discarded and not encountered in
|
||||
* the stream.
|
||||
*
|
||||
* <p> If this pattern does not match any subsequence of the input then
|
||||
* the resulting stream has just one element, namely the input sequence in
|
||||
* string form.
|
||||
*
|
||||
* <p> A zero-length input sequence always results an empty stream.
|
||||
*
|
||||
* <p> When there is a positive-width match at the beginning of the input
|
||||
* sequence then an empty leading substring is included at the beginning
|
||||
* of the stream. A zero-width match at the beginning however never produces
|
||||
|
||||
@ -81,8 +81,10 @@ public class Split {
|
||||
// split() now returns 0-length for empty source "" see #6559590
|
||||
source = "";
|
||||
String[] result = source.split("e", 0);
|
||||
if (result.length != 0)
|
||||
if (result.length != 1)
|
||||
throw new RuntimeException("String.split failure 8");
|
||||
if (!result[0].equals(source))
|
||||
throw new RuntimeException("String.split failure 9");
|
||||
|
||||
// check fastpath of String.split()
|
||||
source = "0123456789abcdefgABCDEFG";
|
||||
|
||||
@ -1781,7 +1781,9 @@ public class RegExTest {
|
||||
// split() now returns 0-length for empty source "" see #6559590
|
||||
source = "";
|
||||
result = source.split("e", 0);
|
||||
if (result.length != 0)
|
||||
if (result.length != 1)
|
||||
failCount++;
|
||||
if (!result[0].equals(source))
|
||||
failCount++;
|
||||
|
||||
// Check both split() and splitAsStraem(), especially for zero-lenth
|
||||
@ -1817,8 +1819,8 @@ public class RegExTest {
|
||||
{ "Abc", "Efg", "Hij" },
|
||||
{ "Abc", "Efg" },
|
||||
{ "Abc" },
|
||||
{},
|
||||
{},
|
||||
{ "" },
|
||||
{ "" },
|
||||
|
||||
{ "awgqwefg1fefw", "vssv1vvv1" },
|
||||
{ "afbfq", "bgwgb", "wngnwggw", "", "hjrnhneerh" },
|
||||
@ -1826,7 +1828,7 @@ public class RegExTest {
|
||||
{ "a\u4ebafg", "fefw\u4eba4\u9f9cvssv\u9f9c", "v\u672c\u672cvv" },
|
||||
{ "1", "23", "456", "7890" },
|
||||
{ "1", "23\u9f9c\u672c\u672c", "456", "\u9f9c\u672c7890" },
|
||||
{},
|
||||
{ "" },
|
||||
{ "This", "is", "testing", "", "with", "different", "separators" },
|
||||
{ "b", "", ":and:f" },
|
||||
{ "b", "", "", "", "", ":and:f" },
|
||||
@ -1834,11 +1836,15 @@ public class RegExTest {
|
||||
};
|
||||
for (int i = 0; i < input.length; i++) {
|
||||
pattern = Pattern.compile(input[i][0]);
|
||||
if (!Arrays.equals(pattern.split(input[i][1]), expected[i]))
|
||||
if (!Arrays.equals(pattern.split(input[i][1]), expected[i])) {
|
||||
failCount++;
|
||||
if (!Arrays.equals(pattern.splitAsStream(input[i][1]).toArray(),
|
||||
expected[i]))
|
||||
}
|
||||
if (input[i][1].length() > 0 && // splitAsStream() return empty resulting
|
||||
// array for zero-length input for now
|
||||
!Arrays.equals(pattern.splitAsStream(input[i][1]).toArray(),
|
||||
expected[i])) {
|
||||
failCount++;
|
||||
}
|
||||
}
|
||||
report("Split");
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user