FULL PRODUCT VERSION :
java version "1.4.2_02"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_02-b03)
Java HotSpot(TM) Client VM (build 1.4.2_02-b03, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows 2000
5.00.2195
Service Pack 3
A DESCRIPTION OF THE PROBLEM :
public String[] split(String regex)
The above method does not work at all if the regex passed to it is "."
And similarly the
public String[] split(String regex, int limit) also fails for the regex ".".
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
public boolean fooMethod()
{
String ipv4Address = "123.23.24.34" ;
System.out.println("IP Address is:"+ipv4Address) ;
String[] fourOctets = ipv4Address.split(".") ;
if(fourOctets == null) System.out.println("fourOctets variable is null") ;
System.out.println("Length of fourOctates is: "+fourOctets.length) ;
boolean allOctetsAreZero = false ;
int numberOfZeroOctets = 0 ;
int tmpOctetVal = 1 ;
for(int i = 0 ; i < 4 ; i++){
tmpOctetVal = Integer.parseInt(fourOctets[i]) ;
if(tmpOctetVal == 0) numberOfZeroOctets++ ;
}
allOctetsAreZero = (numberOfZeroOctets == 4)? true: false ;
return allOctetsAreZero ;
}
=============================================
At the line
tmpOctetVal = Integer.parseInt(fourOctets[i]) ;
it throws null pointer exception. And that's because the fourOctets is an
zero (0) length array returned by the split(".") method.
This bug is exactly similar to 5061438 and i am filing it, because, if you
go by the documentation of the API, it says nothing about meta-characters. So, this is justifiably a bug. Either you fix the API or the documentation. It wasted so much time of mine.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
it should return false for this method
ACTUAL -
it's throwing ArrayIndexOutOfBoundsException at the line
tmpOctetVal = Integer.parseInt(fourOctets[i]) ;
ERROR MESSAGES/STACK TRACES THAT OCCUR :
java.lang.ArrayIndexOutOfBoundsException: 0
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
public boolean fooMethod()
{
String ipv4Address = "123.23.24.34" ;
System.out.println("IP Address is:"+ipv4Address) ;
String[] fourOctets = ipv4Address.split(".") ;
if(fourOctets == null) System.out.println("fourOctets variable is null") ;
System.out.println("Length of fourOctates is: "+fourOctets.length) ;
boolean allOctetsAreZero = false ;
int numberOfZeroOctets = 0 ;
int tmpOctetVal = 1 ;
for(int i = 0 ; i < 4 ; i++){
tmpOctetVal = Integer.parseInt(fourOctets[i]) ;
if(tmpOctetVal == 0) numberOfZeroOctets++ ;
}
allOctetsAreZero = (numberOfZeroOctets == 4)? true: false ;
return allOctetsAreZero ;
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Instead of giving "." -- give "\\." as the regex to the split() method.
But documentation does not say anything on this and it's really eating up time to find this solution.
###@###.### 2005-2-18 06:28:51 GMT
java version "1.4.2_02"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_02-b03)
Java HotSpot(TM) Client VM (build 1.4.2_02-b03, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows 2000
5.00.2195
Service Pack 3
A DESCRIPTION OF THE PROBLEM :
public String[] split(String regex)
The above method does not work at all if the regex passed to it is "."
And similarly the
public String[] split(String regex, int limit) also fails for the regex ".".
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
public boolean fooMethod()
{
String ipv4Address = "123.23.24.34" ;
System.out.println("IP Address is:"+ipv4Address) ;
String[] fourOctets = ipv4Address.split(".") ;
if(fourOctets == null) System.out.println("fourOctets variable is null") ;
System.out.println("Length of fourOctates is: "+fourOctets.length) ;
boolean allOctetsAreZero = false ;
int numberOfZeroOctets = 0 ;
int tmpOctetVal = 1 ;
for(int i = 0 ; i < 4 ; i++){
tmpOctetVal = Integer.parseInt(fourOctets[i]) ;
if(tmpOctetVal == 0) numberOfZeroOctets++ ;
}
allOctetsAreZero = (numberOfZeroOctets == 4)? true: false ;
return allOctetsAreZero ;
}
=============================================
At the line
tmpOctetVal = Integer.parseInt(fourOctets[i]) ;
it throws null pointer exception. And that's because the fourOctets is an
zero (0) length array returned by the split(".") method.
This bug is exactly similar to 5061438 and i am filing it, because, if you
go by the documentation of the API, it says nothing about meta-characters. So, this is justifiably a bug. Either you fix the API or the documentation. It wasted so much time of mine.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
it should return false for this method
ACTUAL -
it's throwing ArrayIndexOutOfBoundsException at the line
tmpOctetVal = Integer.parseInt(fourOctets[i]) ;
ERROR MESSAGES/STACK TRACES THAT OCCUR :
java.lang.ArrayIndexOutOfBoundsException: 0
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
public boolean fooMethod()
{
String ipv4Address = "123.23.24.34" ;
System.out.println("IP Address is:"+ipv4Address) ;
String[] fourOctets = ipv4Address.split(".") ;
if(fourOctets == null) System.out.println("fourOctets variable is null") ;
System.out.println("Length of fourOctates is: "+fourOctets.length) ;
boolean allOctetsAreZero = false ;
int numberOfZeroOctets = 0 ;
int tmpOctetVal = 1 ;
for(int i = 0 ; i < 4 ; i++){
tmpOctetVal = Integer.parseInt(fourOctets[i]) ;
if(tmpOctetVal == 0) numberOfZeroOctets++ ;
}
allOctetsAreZero = (numberOfZeroOctets == 4)? true: false ;
return allOctetsAreZero ;
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Instead of giving "." -- give "\\." as the regex to the split() method.
But documentation does not say anything on this and it's really eating up time to find this solution.
###@###.### 2005-2-18 06:28:51 GMT
- relates to
-
JDK-5061438 String.split produces unexpected output when '|' delimiter is used
-
- Closed
-