changeset 28964:f4a570561f34

8069325: Pattern.splitAsStream does not return input if it is empty and there is no match Reviewed-by: sherman
author psandoz
date Fri, 13 Feb 2015 11:13:30 +0100
parents 8498cdb7c54b
children 9468d534ab8c
files jdk/src/java.base/share/classes/java/util/regex/Pattern.java jdk/test/java/util/regex/PatternStreamTest.java
diffstat 2 files changed, 15 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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});