FULL PRODUCT VERSION :
java version " 1.7.0_25 "
Java(TM) SE Runtime Environment (build 1.7.0_25-b17)
Java HotSpot(TM) 64-Bit Server VM (build 23.25-b01, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]
A DESCRIPTION OF THE PROBLEM :
When used on an empty character sequence the method String.split(String, int) returns an array containing the original String.
According to the documentation of this method one would expect an empty array:
" If n is zero then the pattern will be applied as many times as possible, the array can have any length, and trailing empty strings will be discarded. "
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
System.out.println( " " .split( " , " , 0).length);
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Output should be " 0 "
ACTUAL -
Output is " 1 "
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
package com.Example;
import static org.junit.Assert.*;
import org.junit.Test;
public class StringTest {
@Test
public void testSplitOnEmptyString() {
assertEquals(0, " " .split( " , " , 0).length);
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Check for empty character sequence before calling split()
java version " 1.7.0_25 "
Java(TM) SE Runtime Environment (build 1.7.0_25-b17)
Java HotSpot(TM) 64-Bit Server VM (build 23.25-b01, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]
A DESCRIPTION OF THE PROBLEM :
When used on an empty character sequence the method String.split(String, int) returns an array containing the original String.
According to the documentation of this method one would expect an empty array:
" If n is zero then the pattern will be applied as many times as possible, the array can have any length, and trailing empty strings will be discarded. "
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
System.out.println( " " .split( " , " , 0).length);
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Output should be " 0 "
ACTUAL -
Output is " 1 "
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
package com.Example;
import static org.junit.Assert.*;
import org.junit.Test;
public class StringTest {
@Test
public void testSplitOnEmptyString() {
assertEquals(0, " " .split( " , " , 0).length);
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Check for empty character sequence before calling split()
- duplicates
-
JDK-8066884 emptyString.split(anyString,0) fails to discard trailing empty strings
-
- Closed
-