8069325: Pattern.splitAsStream does not return input if it is empty and there is no match
Reviewed-by: sherman
--- a/jdk/src/java.base/share/classes/java/util/regex/Pattern.java Fri Feb 13 11:13:27 2015 +0100
+++ b/jdk/src/java.base/share/classes/java/util/regex/Pattern.java Fri Feb 13 11:13:30 2015 +0100
@@ -5819,6 +5819,10 @@
MatcherIterator() {
this.matcher = matcher(input);
+ // If the input is an empty string then the result can only be a
+ // stream of the input. Induce that by setting the empty
+ // element count to 1
+ this.emptyElementCount = input.length() == 0 ? 1 : 0;
}
public String next() {
--- a/jdk/test/java/util/regex/PatternStreamTest.java Fri Feb 13 11:13:27 2015 +0100
+++ b/jdk/test/java/util/regex/PatternStreamTest.java Fri Feb 13 11:13:30 2015 +0100
@@ -114,9 +114,20 @@
data.add(new Object[]{description, input, pattern, expected});
+ description = "Empty input";
input = "";
pattern = Pattern.compile("\u56da");
expected = new ArrayList<>();
+ expected.add("");
+
+ data.add(new Object[]{description, input, pattern, expected});
+
+
+ description = "Empty input with empty pattern";
+ input = "";
+ pattern = Pattern.compile("");
+ expected = new ArrayList<>();
+ expected.add("");
data.add(new Object[]{description, input, pattern, expected});