FULL PRODUCT VERSION :
java version "1.7.0_05"
Java(TM) SE Runtime Environment (build 1.7.0_05-b05)
Java HotSpot(TM) Client VM (build 23.1-b03, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]
A DESCRIPTION OF THE PROBLEM :
Unable to store ip address in the range 0.0.0.0 to 0.127.255.255 and 255.128.0.0 to 255.255.255.255 in BigInteger format and then convert back to InetAddress.
Thinks problem with toByteArray() method.
All other ip address ranges works fine.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1.Create InetAddress using the method
InetAddress addInvalidLength3 = InetAddress.getByName("0.126.254.254");
2.Convert it to bigInteger
BigInteger bigIntLngth3 = new BigInteger(addInvalidLength3.getAddress());
3.Convert back to InetAddress.
byte[] bytesVarLength3 = bigIntLngth3.toByteArray();
InetAddress addressIpFormat3 = InetAddress.getByAddress(bytesVarLength3);
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
InetAddress 0.126.254.254
ACTUAL -
java.net.UnknownHostException: addr is of illegal length
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
public class TestClass {
public static void main(String[] args){
try{
/*Inavlid ranges are
* 0.0.0.0 to 0.127.255.255
* 255.128.0.0 to 255.255.255.255
*
* All other ranges works fine.
* Never be able to store IP address in this range in a BigInteger format and
* convert it back to InetAddress from BigInteger
*
*/
InetAddress addInvalidLength3 = InetAddress.getByName("0.126.254.254");
InetAddress addInvalidLength5 = InetAddress.getByName("255.128.22.10");
InetAddress addValidLength4 = InetAddress.getByName("0.128.254.254");
BigInteger bigIntLngth3 = new BigInteger(addInvalidLength3.getAddress());
BigInteger bigIntLngth5 = new BigInteger(addInvalidLength5.getAddress());
BigInteger bigIntLngth4 = new BigInteger(addValidLength4.getAddress());
byte[] bytesVarLength3 = bigIntLngth3.toByteArray();//length will be 3 byte which is invalid
byte[] bytesVarLength5 = bigIntLngth5.toByteArray();//lenght will be 5 byte which is invalid
byte[] bytesVarLength4 = bigIntLngth4.toByteArray();//Correct length
try{
InetAddress addressIpFormat3 = InetAddress.getByAddress(bytesVarLength3);//Exception addr is of illegal length
}catch(Exception ex){
System.out.println("Error for ip 0.126.254.254 "+ex.getMessage());
ex.printStackTrace();
}
try{
InetAddress addressIpFormat5 = InetAddress.getByAddress(bytesVarLength5);//Exception addr is of illegal length
}catch(Exception ex){
System.out.println("Error for ip 255.128.22.10 "+ex.getMessage());
ex.printStackTrace();
}
try{
InetAddress addressIpFormat4 = InetAddress.getByAddress(bytesVarLength4);//Works Fine
}catch(Exception ex){
//It wont come here..
System.out.println("Error for ip 0.128.254.254 "+ex.getMessage());
ex.printStackTrace();
}
}catch(Exception ex){
ex.printStackTrace();
}
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
If length of bytes is greater than 4, remove the most significant bit to make it 4 byte length.
For bytes with length less than 3. no work around known.
java version "1.7.0_05"
Java(TM) SE Runtime Environment (build 1.7.0_05-b05)
Java HotSpot(TM) Client VM (build 23.1-b03, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]
A DESCRIPTION OF THE PROBLEM :
Unable to store ip address in the range 0.0.0.0 to 0.127.255.255 and 255.128.0.0 to 255.255.255.255 in BigInteger format and then convert back to InetAddress.
Thinks problem with toByteArray() method.
All other ip address ranges works fine.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1.Create InetAddress using the method
InetAddress addInvalidLength3 = InetAddress.getByName("0.126.254.254");
2.Convert it to bigInteger
BigInteger bigIntLngth3 = new BigInteger(addInvalidLength3.getAddress());
3.Convert back to InetAddress.
byte[] bytesVarLength3 = bigIntLngth3.toByteArray();
InetAddress addressIpFormat3 = InetAddress.getByAddress(bytesVarLength3);
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
InetAddress 0.126.254.254
ACTUAL -
java.net.UnknownHostException: addr is of illegal length
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
public class TestClass {
public static void main(String[] args){
try{
/*Inavlid ranges are
* 0.0.0.0 to 0.127.255.255
* 255.128.0.0 to 255.255.255.255
*
* All other ranges works fine.
* Never be able to store IP address in this range in a BigInteger format and
* convert it back to InetAddress from BigInteger
*
*/
InetAddress addInvalidLength3 = InetAddress.getByName("0.126.254.254");
InetAddress addInvalidLength5 = InetAddress.getByName("255.128.22.10");
InetAddress addValidLength4 = InetAddress.getByName("0.128.254.254");
BigInteger bigIntLngth3 = new BigInteger(addInvalidLength3.getAddress());
BigInteger bigIntLngth5 = new BigInteger(addInvalidLength5.getAddress());
BigInteger bigIntLngth4 = new BigInteger(addValidLength4.getAddress());
byte[] bytesVarLength3 = bigIntLngth3.toByteArray();//length will be 3 byte which is invalid
byte[] bytesVarLength5 = bigIntLngth5.toByteArray();//lenght will be 5 byte which is invalid
byte[] bytesVarLength4 = bigIntLngth4.toByteArray();//Correct length
try{
InetAddress addressIpFormat3 = InetAddress.getByAddress(bytesVarLength3);//Exception addr is of illegal length
}catch(Exception ex){
System.out.println("Error for ip 0.126.254.254 "+ex.getMessage());
ex.printStackTrace();
}
try{
InetAddress addressIpFormat5 = InetAddress.getByAddress(bytesVarLength5);//Exception addr is of illegal length
}catch(Exception ex){
System.out.println("Error for ip 255.128.22.10 "+ex.getMessage());
ex.printStackTrace();
}
try{
InetAddress addressIpFormat4 = InetAddress.getByAddress(bytesVarLength4);//Works Fine
}catch(Exception ex){
//It wont come here..
System.out.println("Error for ip 0.128.254.254 "+ex.getMessage());
ex.printStackTrace();
}
}catch(Exception ex){
ex.printStackTrace();
}
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
If length of bytes is greater than 4, remove the most significant bit to make it 4 byte length.
For bytes with length less than 3. no work around known.