leosimons    2004/01/11 14:33:32

  Modified:    framework/api/src/java/org/apache/avalon/framework
                        Version.java
  Log:
  Version was not checking for null values, hence it was not failing gracefully. I've 
added checks for null and modified the behaviour appropriately. The only impact will 
be on applications that expect NPEs on comparing with a null object. Which I really 
hope don't exist :D
  
  Revision  Changes    Path
  1.31      +16 -2     
avalon/framework/api/src/java/org/apache/avalon/framework/Version.java
  
  Index: Version.java
  ===================================================================
  RCS file: 
/home/cvs/avalon/framework/api/src/java/org/apache/avalon/framework/Version.java,v
  retrieving revision 1.30
  retrieving revision 1.31
  diff -u -r1.30 -r1.31
  --- Version.java      12 Jul 2003 16:49:55 -0000      1.30
  +++ Version.java      11 Jan 2004 22:33:32 -0000      1.31
  @@ -105,11 +105,15 @@
        * @return the new Version object
        * @throws NumberFormatException if an error occurs
        * @throws IllegalArgumentException if an error occurs
  +     * @throws NullPointerException if the provided string is <code>null</code>
        * @since 4.1
        */
       public static Version getVersion( final String version )
           throws NumberFormatException, IllegalArgumentException
       {
  +        if( version == null )
  +            throw new NullPointerException( "version" );
  +
           final StringTokenizer tokenizer = new StringTokenizer( version, "." );
           final String[] levels = new String[ tokenizer.countTokens() ];
           for( int i = 0; i < levels.length; i++ )
  @@ -199,6 +203,9 @@
        */
       public boolean equals( final Version other )
       {
  +        if( other == null )
  +            return false;
  +
           boolean isEqual = ( getMajor() == other.getMajor() );
           
           if ( isEqual )
  @@ -284,6 +291,9 @@
        */
       public boolean complies( final Version other )
       {
  +        if( other == null )
  +            return false;
  +
           if( other.m_major == -1 )
           {
               return true;
  @@ -322,11 +332,15 @@
   
       /**
        * Compare two versions together according to the
  -     * Comparable interface.
  +     * [EMAIL PROTECTED] Comparable} interface.
        * 
        * @return number indicating relative value (-1, 0, 1)
        */
       public int compareTo(Object o) {
  +        if( o == null )
  +            throw new NullPointerException( "o" );
  +
  +
           Version other = (Version)o;
           int val = 0;
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to