FULL PRODUCT VERSION :
java version "1.6.0-beta2"
Java(TM) SE Runtime Environment (build 1.6.0-beta2-b86)
Java HotSpot(TM) Client VM (build 1.6.0-beta2-b86, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Linux localhost 2.6.17-1mdk #1 Fri Jul 21 09:47:28 CDT 2006 i686 Intel(R) Pentium(R) 4 CPU 2.66GHz Mandriva Linux
A DESCRIPTION OF THE PROBLEM :
When a null value is passed to Float.parseFloat() or Double.parseDouble(), a NullPointerException is thrown, which is not mentioned in the API Specifications. Additionally, this exception is wrapped in a NumberFormatException if Integer.parseInt() or Long.parseLong() is used. Wouldn't it be better if these methods handle this the same way?
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
See the code below
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Integer: java.lang.NumberFormatException: null
Long: java.lang.NumberFormatException: null
Float: java.lang.NumberFormatException: null
Double java.lang.NumberFormatException: null
ACTUAL -
Integer: java.lang.NumberFormatException: null
Long: java.lang.NumberFormatException: null
Float: java.lang.NullPointerException
Double java.lang.NullPointerException
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
public class Test {
	
	
public static void main(String[] args) {
		
try {
Integer.parseInt(null);
} catch (Exception ex) {
System.out.println(ex);
}
		
try {
Long.parseLong(null);
} catch (Exception ex) {
System.out.println(ex);
}
		
try {
Float.parseFloat(null);
} catch (Exception ex) {
System.out.println(ex);
}
		
try {
Double.parseDouble(null);
} catch (Exception ex) {
System.out.println(ex);
}
		
} // end main
	
	
} // end class
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
We need to catch an additional NullPointerException to ensure the reliability of our code.
            
java version "1.6.0-beta2"
Java(TM) SE Runtime Environment (build 1.6.0-beta2-b86)
Java HotSpot(TM) Client VM (build 1.6.0-beta2-b86, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Linux localhost 2.6.17-1mdk #1 Fri Jul 21 09:47:28 CDT 2006 i686 Intel(R) Pentium(R) 4 CPU 2.66GHz Mandriva Linux
A DESCRIPTION OF THE PROBLEM :
When a null value is passed to Float.parseFloat() or Double.parseDouble(), a NullPointerException is thrown, which is not mentioned in the API Specifications. Additionally, this exception is wrapped in a NumberFormatException if Integer.parseInt() or Long.parseLong() is used. Wouldn't it be better if these methods handle this the same way?
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
See the code below
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Integer: java.lang.NumberFormatException: null
Long: java.lang.NumberFormatException: null
Float: java.lang.NumberFormatException: null
Double java.lang.NumberFormatException: null
ACTUAL -
Integer: java.lang.NumberFormatException: null
Long: java.lang.NumberFormatException: null
Float: java.lang.NullPointerException
Double java.lang.NullPointerException
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
public class Test {
public static void main(String[] args) {
try {
Integer.parseInt(null);
} catch (Exception ex) {
System.out.println(ex);
}
try {
Long.parseLong(null);
} catch (Exception ex) {
System.out.println(ex);
}
try {
Float.parseFloat(null);
} catch (Exception ex) {
System.out.println(ex);
}
try {
Double.parseDouble(null);
} catch (Exception ex) {
System.out.println(ex);
}
} // end main
} // end class
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
We need to catch an additional NullPointerException to ensure the reliability of our code.
- duplicates
- 
                    JDK-7133642 Double.parseDouble(null) throws NullPointerExeption, not NumberFormatExcep -           
- Closed
 
-         
- relates to
- 
                    JDK-1231955 No direct way to convert from String to float or double -           
- Closed
 
-         
- 
                    JDK-4787924 Integer.parseInt() and Double.parseDoube() throw different exceptions on null -           
- Closed
 
-         
- 
                    JDK-8264745 Unify ParseLong Methods to Throw NPE -           
- Closed
 
-