Skip to content
This repository has been archived by the owner on Nov 19, 2021. It is now read-only.

Commit

Permalink
TFJ-205 NullPoinerException in HttpClient.equals()
Browse files Browse the repository at this point in the history
git-svn-id: http://yusuke.homeip.net/svn/twitter4j/trunk@373 117b7e0d-5933-0410-9d29-ab41bb01d86b
  • Loading branch information
yusuke committed Sep 7, 2009
1 parent 8bfea6b commit b5c60ac
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 22 deletions.
68 changes: 46 additions & 22 deletions src/main/java/twitter4j/http/HttpClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -605,11 +605,47 @@ private HttpURLConnection getConnection(String url) throws IOException {
return con;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof HttpClient)) return false;

HttpClient that = (HttpClient) o;

if (connectionTimeout != that.connectionTimeout) return false;
if (proxyPort != that.proxyPort) return false;
if (readTimeout != that.readTimeout) return false;
if (retryCount != that.retryCount) return false;
if (retryIntervalMillis != that.retryIntervalMillis) return false;
if (accessTokenURL != null ? !accessTokenURL.equals(that.accessTokenURL) : that.accessTokenURL != null)
return false;
if (!authenticationURL.equals(that.authenticationURL)) return false;
if (!authorizationURL.equals(that.authorizationURL)) return false;
if (basic != null ? !basic.equals(that.basic) : that.basic != null)
return false;
if (oauth != null ? !oauth.equals(that.oauth) : that.oauth != null)
return false;
if (oauthToken != null ? !oauthToken.equals(that.oauthToken) : that.oauthToken != null)
return false;
if (password != null ? !password.equals(that.password) : that.password != null)
return false;
if (proxyAuthPassword != null ? !proxyAuthPassword.equals(that.proxyAuthPassword) : that.proxyAuthPassword != null)
return false;
if (proxyAuthUser != null ? !proxyAuthUser.equals(that.proxyAuthUser) : that.proxyAuthUser != null)
return false;
if (proxyHost != null ? !proxyHost.equals(that.proxyHost) : that.proxyHost != null)
return false;
if (!requestHeaders.equals(that.requestHeaders)) return false;
if (!requestTokenURL.equals(that.requestTokenURL)) return false;
if (userId != null ? !userId.equals(that.userId) : that.userId != null)
return false;

return true;
}

@Override
public int hashCode() {
int result = OK;
result = 31 * result + (DEBUG ? 1 : 0);
result = 31 * result + (basic != null ? basic.hashCode() : 0);
int result = basic != null ? basic.hashCode() : 0;
result = 31 * result + retryCount;
result = 31 * result + retryIntervalMillis;
result = 31 * result + (userId != null ? userId.hashCode() : 0);
Expand All @@ -620,28 +656,16 @@ public int hashCode() {
result = 31 * result + (proxyAuthPassword != null ? proxyAuthPassword.hashCode() : 0);
result = 31 * result + connectionTimeout;
result = 31 * result + readTimeout;
result = 31 * result + (isJDK14orEarlier ? 1 : 0);
result = 31 * result + (requestHeaders != null ? requestHeaders.hashCode() : 0);
result = 31 * result + requestHeaders.hashCode();
result = 31 * result + (oauth != null ? oauth.hashCode() : 0);
result = 31 * result + requestTokenURL.hashCode();
result = 31 * result + authorizationURL.hashCode();
result = 31 * result + authenticationURL.hashCode();
result = 31 * result + (accessTokenURL != null ? accessTokenURL.hashCode() : 0);
result = 31 * result + (oauthToken != null ? oauthToken.hashCode() : 0);
return result;
}

@Override
public boolean equals(Object obj) {
if (null == obj) {
return false;
}
if (this == obj) {
return true;
}
if (obj instanceof HttpClient) {
HttpClient that = (HttpClient) obj;
return this.retryIntervalMillis
== that.retryIntervalMillis && this.basic.equals(that.basic)
&& this.requestHeaders.equals(that.requestHeaders);
}
return false;
}

private static void log(String message) {
if (DEBUG) {
System.out.println("[" + new java.util.Date() + "]" + message);
Expand Down
8 changes: 8 additions & 0 deletions src/test/java/twitter4j/http/OAuthTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,14 @@ protected void tearDown() throws Exception{

}

public void testDeterministic() throws Exception{
Twitter twitter1 = new Twitter();
twitter1.setOAuthConsumer(browserConsumerKey, browserConsumerSecret);
Twitter twitter2 = new Twitter();
twitter2.setOAuthConsumer(browserConsumerKey, browserConsumerSecret);
assertEquals(twitter1, twitter2);
}

public void testDesktopClient() throws Exception{
RequestToken rt;
Twitter twitter = new Twitter();
Expand Down

0 comments on commit b5c60ac

Please sign in to comment.