You are viewing a plain text version of this content. The canonical link for it is here.
Posted to wagon-commits@maven.apache.org by br...@apache.org on 2008/05/14 13:18:32 UTC

svn commit: r656236 - /maven/wagon/trunk/wagon-provider-api/src/main/java/org/apache/maven/wagon/repository/Repository.java

Author: brett
Date: Wed May 14 04:18:32 2008
New Revision: 656236

URL: http://svn.apache.org/viewvc?rev=656236&view=rev
Log:
[WAGON-105] guard against NPE in hashCode

Modified:
    maven/wagon/trunk/wagon-provider-api/src/main/java/org/apache/maven/wagon/repository/Repository.java

Modified: maven/wagon/trunk/wagon-provider-api/src/main/java/org/apache/maven/wagon/repository/Repository.java
URL: http://svn.apache.org/viewvc/maven/wagon/trunk/wagon-provider-api/src/main/java/org/apache/maven/wagon/repository/Repository.java?rev=656236&r1=656235&r2=656236&view=diff
==============================================================================
--- maven/wagon/trunk/wagon-provider-api/src/main/java/org/apache/maven/wagon/repository/Repository.java (original)
+++ maven/wagon/trunk/wagon-provider-api/src/main/java/org/apache/maven/wagon/repository/Repository.java Wed May 14 04:18:32 2008
@@ -66,6 +66,9 @@
 
     private String password = null;
 
+    /**
+     * @deprecated use {@link #Repository(String, String)}
+     */
     public Repository()
     {
 
@@ -73,8 +76,18 @@
 
     public Repository( String id, String url )
     {
+        if ( id == null )
+        {
+            throw new NullPointerException( "id can not be null" );
+        }
+        
         setId( id );
 
+        if ( url == null )
+        {
+            throw new NullPointerException( "url can not be null" );
+        }
+        
         setUrl( url );
     }
 
@@ -88,7 +101,6 @@
         this.id = id;
     }
 
-
     public String getBasedir()
     {
         return basedir;
@@ -238,18 +250,31 @@
         this.parameters = parameters;
     }
 
-    // ========================================================================
-    // id is the unique identifier for Repositories, so let's enforce that.
-    // ========================================================================
-    public boolean equals( Object other )
-    {
-        return ( other == this ||
-            ( ( other instanceof Repository ) && ( (Repository) other ).getId().equals( getId() ) ) );
-    }
-
     public int hashCode()
     {
-        return getId().hashCode();
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + ( ( id == null ) ? 0 : id.hashCode() );
+        return result;
+    }
+
+    public boolean equals( Object obj )
+    {
+        if ( this == obj )
+            return true;
+        if ( obj == null )
+            return false;
+        if ( getClass() != obj.getClass() )
+            return false;
+        final Repository other = (Repository) obj;
+        if ( id == null )
+        {
+            if ( other.id != null )
+                return false;
+        }
+        else if ( !id.equals( other.id ) )
+            return false;
+        return true;
     }
 
     public String getUsername()



---------------------------------------------------------------------
To unsubscribe, e-mail: wagon-commits-unsubscribe@maven.apache.org
For additional commands, e-mail: wagon-commits-help@maven.apache.org