commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dgra...@apache.org
Subject cvs commit: jakarta-commons/validator/src/share/org/apache/commons/validator GenericTypeValidator.java
Date Sun, 25 May 2003 18:29:52 GMT
dgraham     2003/05/25 11:29:52

  Modified:    validator/src/share/org/apache/commons/validator
                        GenericTypeValidator.java
  Log:
  Catch NumberFormatException instead of Exception and document 
  places that swallow exceptions.
  
  Revision  Changes    Path
  1.8       +52 -48    jakarta-commons/validator/src/share/org/apache/commons/validator/GenericTypeValidator.java
  
  Index: GenericTypeValidator.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/validator/src/share/org/apache/commons/validator/GenericTypeValidator.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- GenericTypeValidator.java	24 May 2003 17:15:25 -0000	1.7
  +++ GenericTypeValidator.java	25 May 2003 18:29:51 -0000	1.8
  @@ -85,15 +85,16 @@
        * @param value The value validation is being performed on.
        */
       public static Byte formatByte(String value) {
  -       Byte result = null;
  -       
  +        if (value == null) {
  +            return null;
  +        }
  +                
          try {
  -          result = new Byte(value);
  -       } catch (Exception e) {
  -            // TODO Why are we catching Exception?  Should this be NumberFormatException?
  +          return new Byte(value);
  +       } catch (NumberFormatException e) {
  +            return null;
          }
          
  -       return result;
       }
   
       /**
  @@ -102,15 +103,16 @@
        * @param value The value validation is being performed on.
        */
       public static Short formatShort(String value) {
  -       Short result = null;
  -       
  +        if (value == null) {
  +            return null;
  +        }
  +                
          try {
  -          result = new Short(value);
  -       } catch (Exception e) {
  -           // TODO Why are we catching Exception?  Should this be NumberFormatException?
  +          return new Short(value);
  +       } catch (NumberFormatException e) {
  +           return null;
          }
  -       
  -       return result;
  +      
       }
   
       /**
  @@ -119,15 +121,16 @@
        * @param value The value validation is being performed on.
        */
   	public static Integer formatInt(String value) {
  -		Integer result = null;
  -
  +        if (value == null) {
  +            return null;
  +        }
  +                
   		try {
  -			result = new Integer(value);
  -		} catch (Exception e) {
  -			// TODO Why are we catching Exception?  Should this be NumberFormatException?
  +			return new Integer(value);
  +		} catch (NumberFormatException e) {
  +			return null;
   		}
  -
  -		return result;
  +        
   	}
   
       /**
  @@ -136,15 +139,16 @@
        * @param value The value validation is being performed on.
        */
       public static Long formatLong(String value) {
  -       Long result = null;
  -       
  +        if (value == null) {
  +            return null;
  +        }
  +        
          try {
  -          result = new Long(value);
  -       } catch (Exception e) {
  -            // TODO Why are we catching Exception?  Should this be NumberFormatException?
  +          return new Long(value);
  +       } catch (NumberFormatException e) {
  +            return null;
          }
          
  -       return result;
       }
   
       /**
  @@ -153,15 +157,16 @@
        * @param value The value validation is being performed on.
        */
       public static Float formatFloat(String value) {
  -       Float result = null;
  -       
  -       try {
  -          result = new Float(value);
  -       } catch (Exception e) {
  -            // TODO Why are we catching Exception?  Should this be NumberFormatException?
  -       }
  -       
  -       return result;
  +        if (value == null) {
  +            return null;
  +        }
  +
  +        try {
  +            return new Float(value);
  +        } catch (NumberFormatException e) {
  +            return null;
  +        }
  +
       }
   
       /**
  @@ -170,15 +175,16 @@
        * @param value The value validation is being performed on.
        */
       public static Double formatDouble(String value) {
  -       Double result = null;
  +        if (value == null) {
  +            return null;
  +        }
          
          try {
  -          result = new Double(value);
  -       } catch (Exception e) {
  -            // TODO Why are we catching Exception?  Should this be NumberFormatException?
  +          return new Double(value);
  +       } catch (NumberFormatException e) {
  +            return null;
          }
          
  -       return result;
       }
   
       /**
  @@ -212,8 +218,7 @@
   
   			date = formatter.parse(value);
   		} catch (ParseException e) {
  -			// TODO Should either document why exception is swallowed or 
  -			// not swallow it.
  +			// Bad date so return null
   		}
   
   		return date;
  @@ -251,8 +256,7 @@
   				}
   			}
   		} catch (ParseException e) {
  -			// TODO Should either document why exception is swallowed or 
  -			// not swallow it.
  +			// Bad date so return null
   		}
   
   		return date;
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message