Skip to content

Commit

Permalink
generics warnings fixes
Browse files Browse the repository at this point in the history
This commit does not change any functionality, just
alters generics to reduce warnings in Eclipse.
  • Loading branch information
Travis Wellman committed Jun 22, 2012
1 parent e1f5bc5 commit 6626b44
Show file tree
Hide file tree
Showing 43 changed files with 176 additions and 196 deletions.
Expand Up @@ -61,8 +61,8 @@
*
* @version $Revision$ $Date$
*/
@SuppressWarnings({"serial","unchecked"}) // <- HERITRIX CHANGE
public class Cookie extends NameValuePair implements Serializable, Comparator {
@SuppressWarnings({"serial"}) // <- HERITRIX CHANGE
public class Cookie extends NameValuePair implements Serializable, Comparator<Cookie> {

// ----------------------------------------------------------- Constructors

Expand Down Expand Up @@ -415,6 +415,7 @@ public int hashCode() {
* @param obj The object to compare against.
* @return true if the two objects are equal.
*/
@Override
public boolean equals(Object obj) {
if (obj == null) return false;
if (this == obj) return true;
Expand Down Expand Up @@ -454,7 +455,8 @@ public String toExternalForm() {
* @param o2 The second object to be compared
* @return See {@link java.util.Comparator#compare(Object,Object)}
*/
public int compare(Object o1, Object o2) {
@Override
public int compare(Cookie o1, Cookie o2) {
LOG.trace("enter Cookie.compare(Object, Object)");

if (!(o1 instanceof Cookie)) {
Expand Down
Expand Up @@ -91,7 +91,6 @@
*
* @version $Revision$ $Date$
*/
@SuppressWarnings("unchecked") // <- HERITRIX CHANGE
public class HttpConnection {

// ----------------------------------------------------------- Constructors
Expand Down Expand Up @@ -1162,7 +1161,7 @@ public void shutdownOutput() {
// Socket.shutdownOutput is a JDK 1.3
// method. We'll use reflection in case
// we're running in an older VM
Class[] paramsClasses = new Class[0];
Class<?>[] paramsClasses = new Class[0];
Method shutdownOutput =
socket.getClass().getMethod("shutdownOutput", paramsClasses);
Object[] params = new Object[0];
Expand Down
Expand Up @@ -94,7 +94,7 @@
*
* @version $Revision$ $Date$
*/
@SuppressWarnings({"deprecation","unchecked"}) // <- // IA/HERITRIX change
@SuppressWarnings({"deprecation"}) // <- // IA/HERITRIX change
public abstract class HttpMethodBase implements HttpMethod {

// -------------------------------------------------------------- Constants
Expand Down Expand Up @@ -1145,8 +1145,9 @@ private CookieSpec getCookieSpec(final HttpState state) {
} else {
this.cookiespec = CookiePolicy.getSpecByPolicy(i);
}
this.cookiespec.setValidDateFormats(
(Collection)this.params.getParameter(HttpMethodParams.DATE_PATTERNS));
@SuppressWarnings("unchecked")
Collection<String> val = (Collection<String>)this.params.getParameter(HttpMethodParams.DATE_PATTERNS);
this.cookiespec.setValidDateFormats(val);
}
return this.cookiespec;
}
Expand Down
Expand Up @@ -47,7 +47,6 @@
*
* @since 2.0beta1
*/
@SuppressWarnings("unchecked") // <- IA/HERITRIX CHANGE
public class HttpParser {

/** Log object for this class. */
Expand Down Expand Up @@ -159,7 +158,7 @@ public static String readLine(InputStream inputStream) throws IOException {
public static Header[] parseHeaders(InputStream is, String charset) throws IOException, HttpException {
LOG.trace("enter HeaderParser.parseHeaders(InputStream, String)");

ArrayList headers = new ArrayList();
ArrayList<Header> headers = new ArrayList<Header>();
String name = null;
StringBuffer value = null;
for (; ;) {
Expand Down
51 changes: 24 additions & 27 deletions commons/src/main/java/org/apache/commons/httpclient/HttpState.java
Expand Up @@ -30,23 +30,21 @@
package org.apache.commons.httpclient;

import java.util.ArrayList;
import java.util.Collection; // <- IA/HERITRIX CHANGE
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.List;
import java.util.Iterator;
import java.util.SortedMap; // <- IA/HERITRIX CHANGE
import java.util.TreeMap; // <- IA/HERITRIX CHANGE
import java.util.Map;
import java.util.SortedMap;
import java.util.concurrent.ConcurrentSkipListMap;

import org.apache.commons.httpclient.cookie.CookieSpec;
import org.apache.commons.httpclient.auth.AuthScope;
import org.apache.commons.httpclient.cookie.CookiePolicy;
import org.apache.commons.httpclient.auth.AuthScope;
import org.apache.commons.httpclient.cookie.CookieSpec;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.sleepycat.collections.StoredIterator; // <- IA/HERITRIX CHANGE
import com.sleepycat.collections.StoredIterator;

/**
* <p>
Expand All @@ -67,7 +65,6 @@
* @version $Revision$ $Date$
*
*/
@SuppressWarnings({"unchecked","unused"}) // <- IA/HERITRIX CHANGE
public class HttpState {

// ----------------------------------------------------- Instance Variables
Expand All @@ -76,13 +73,13 @@ public class HttpState {
* Map of {@link Credentials credentials} by realm that this
* HTTP state contains.
*/
private HashMap credMap = new HashMap();
private HashMap<AuthScope, Credentials> credMap = new HashMap<AuthScope, Credentials>();

/**
* Map of {@link Credentials proxy credentials} by realm that this
* HTTP state contains
*/
private HashMap proxyCred = new HashMap();
private HashMap<AuthScope, Credentials> proxyCred = new HashMap<AuthScope, Credentials>();

// BEGIN IA/HERITRIX CHANGES
// /**
Expand All @@ -92,7 +89,7 @@ public class HttpState {
/**
* SortedMap of {@link Cookie cookies} that this HTTP state contains.
*/
private SortedMap cookiesMap = new ConcurrentSkipListMap();
private SortedMap<String, Cookie> cookiesMap = new ConcurrentSkipListMap<String, Cookie>();
// END IA/HERITRIX CHANGES

private boolean preemptive = false;
Expand Down Expand Up @@ -200,8 +197,8 @@ public synchronized Cookie[] getCookies() {
// BEGIN IA/HERITRIX CHANGES
// PRIOR IMPL & COMPARISON HARNESS LEFT COMMENTED OUT FOR TEMPORARY REFERENCE
// Cookie[] arrayListAnswer = (Cookie[]) (cookiesArrayList.toArray(new Cookie[cookiesArrayList.size()]));
ArrayList arrayableCookies = new ArrayList();
Iterator iter = cookiesMap.values().iterator();
ArrayList<Cookie> arrayableCookies = new ArrayList<Cookie>();
Iterator<Cookie> iter = cookiesMap.values().iterator();
while(iter.hasNext()) {
arrayableCookies.add(iter.next());
}
Expand All @@ -226,7 +223,7 @@ public synchronized Cookie[] getCookies() {
*
* @return sorter map of {@link Cookie cookies}
*/
public SortedMap getCookiesMap() {
public SortedMap<String, Cookie> getCookiesMap() {
return cookiesMap;
}

Expand All @@ -236,7 +233,7 @@ public SortedMap getCookiesMap() {
*
* @param map alternate sorted map to use to store cookies
*/
public void setCookiesMap(SortedMap map) {
public void setCookiesMap(SortedMap<String, Cookie> map) {
this.cookiesMap = map;
}
// END IA/HERITRIX ADDITIONS
Expand Down Expand Up @@ -321,9 +318,9 @@ public synchronized boolean purgeExpiredCookies(Date date) {
// }
// }
boolean removed = false;
Iterator it = cookiesMap.values().iterator();
Iterator<Cookie> it = cookiesMap.values().iterator();
while (it.hasNext()) {
if (((Cookie) (it.next())).isExpired(date)) {
if (it.next().isExpired(date)) {
it.remove();
removed = true;
}
Expand Down Expand Up @@ -457,15 +454,15 @@ public synchronized void setCredentials(final AuthScope authscope, final Credent
* @return the credentials
*
*/
private static Credentials matchCredentials(final HashMap map, final AuthScope authscope) {
private static Credentials matchCredentials(final HashMap<AuthScope, Credentials> map, final AuthScope authscope) {
// see if we get a direct hit
Credentials creds = (Credentials)map.get(authscope);
Credentials creds = map.get(authscope);
if (creds == null) {
// Nope.
// Do a full scan
int bestMatchFactor = -1;
AuthScope bestMatch = null;
Iterator items = map.keySet().iterator();
Iterator<AuthScope> items = map.keySet().iterator();
while (items.hasNext()) {
AuthScope current = (AuthScope)items.next();
int factor = authscope.match(current);
Expand Down Expand Up @@ -649,12 +646,12 @@ public synchronized String toString() {
* @param credMap The credentials.
* @return The string representation.
*/
private static String getCredentialsStringRepresentation(final Map credMap) {
private static String getCredentialsStringRepresentation(final Map<AuthScope, Credentials> credMap) {
StringBuffer sbResult = new StringBuffer();
Iterator iter = credMap.keySet().iterator();
Iterator<AuthScope> iter = credMap.keySet().iterator();
while (iter.hasNext()) {
Object key = iter.next();
Credentials cred = (Credentials) credMap.get(key);
Credentials cred = credMap.get(key);
if (sbResult.length() > 0) {
sbResult.append(", ");
}
Expand All @@ -670,11 +667,11 @@ private static String getCredentialsStringRepresentation(final Map credMap) {
* @param cookies The cookies
* @return The string representation.
*/
private static String getCookiesStringRepresentation(final Collection cookies) { // <- IA/HERITRIX CHANGE
private static String getCookiesStringRepresentation(final Collection<Cookie> cookies) { // <- IA/HERITRIX CHANGE
StringBuffer sbResult = new StringBuffer();
Iterator iter = cookies.iterator();
Iterator<Cookie> iter = cookies.iterator();
while (iter.hasNext()) {
Cookie ck = (Cookie) iter.next();
Cookie ck = iter.next();
if (sbResult.length() > 0) {
sbResult.append("#");
}
Expand Down
Expand Up @@ -51,7 +51,6 @@
*
* @since 2.0
*/
@SuppressWarnings("unchecked") // <- IA/HERITRIX CHANGE
public interface CookieSpec {

/** Path delimiter */
Expand Down Expand Up @@ -140,15 +139,15 @@ void validate(String host, int port, String path, boolean secure,
*
* @param datepatterns collection of date patterns
*/
void setValidDateFormats(Collection datepatterns);
void setValidDateFormats(Collection<String> datepatterns);

/**
* Returns the {@link Collection} of date patterns used for parsing. The String patterns are compatible
* with the {@link java.text.SimpleDateFormat}.
*
* @return collection of date patterns
*/
Collection getValidDateFormats();
Collection<String> getValidDateFormats();

/**
* Determines if a Cookie matches a location.
Expand Down Expand Up @@ -195,15 +194,15 @@ Cookie[] match(String host, int port, String path, boolean secure,
*
* @param host the host to which the request is being submitted
* @param port the port to which the request is being submitted
* (currenlty ignored)
* (currently ignored)
* @param path the path to which the request is being submitted
* @param secure <tt>true</tt> if the request is using a secure protocol
* @param cookies SortedMap of <tt>Cookie</tt>s to be matched
*
* @return <tt>true</tt> if the cookie should be submitted with a request
* with given attributes, <tt>false</tt> otherwise.
*/
Cookie[] match(String domain, int port, String path, boolean secure, SortedMap cookiesMap);
Cookie[] match(String domain, int port, String path, boolean secure, SortedMap<String, Cookie> cookiesMap);
// END IA/HERITRIX CHANGES

/**
Expand Down
Expand Up @@ -65,14 +65,13 @@
*
* @since 2.0
*/
@SuppressWarnings("unchecked") // <- IA/HERITRIX CHANGE
public class CookieSpecBase implements CookieSpec {

/** Log object */
protected static final Log LOG = LogFactory.getLog(CookieSpec.class);

/** Valid date patterns */
private Collection datepatterns = null;
private Collection<String> datepatterns = null;

/** Default constructor */
public CookieSpecBase() {
Expand Down Expand Up @@ -346,11 +345,13 @@ public void parseAttribute(
}


public Collection getValidDateFormats() {
@Override
public Collection<String> getValidDateFormats() {
return this.datepatterns;
}

public void setValidDateFormats(final Collection datepatterns) {
@Override
public void setValidDateFormats(final Collection<String> datepatterns) {
this.datepatterns = datepatterns;
}

Expand Down Expand Up @@ -580,7 +581,7 @@ public Cookie[] match(String host, int port, String path,
if (cookies == null) {
return null;
}
List matching = new LinkedList();
List<Cookie> matching = new LinkedList<Cookie>();
for (int i = 0; i < cookies.length; i++) {
if (match(host, port, path, secure, cookies[i])) {
addInPathOrder(matching, cookies[i]);
Expand All @@ -606,17 +607,17 @@ public Cookie[] match(String host, int port, String path,
* @param cookies SortedMap of <tt>Cookie</tt>s to be matched
* @return an array of <tt>Cookie</tt>s matching the criterium
*/

@Override
public Cookie[] match(String host, int port, String path,
boolean secure, final SortedMap cookies) {
boolean secure, final SortedMap<String, Cookie> cookies) {

LOG.trace("enter CookieSpecBase.match("
+ "String, int, String, boolean, SortedMap)");

if (cookies == null) {
return null;
}
List matching = new LinkedList();
List<Cookie> matching = new LinkedList<Cookie>();
InternetDomainName domain;
try {
domain = InternetDomainName.fromLenient(host);
Expand All @@ -626,7 +627,7 @@ public Cookie[] match(String host, int port, String path,

String candidate = (domain!=null) ? domain.name() : host;
while(candidate!=null) {
Iterator iter = cookies.subMap(candidate,
Iterator<Cookie> iter = cookies.subMap(candidate,
candidate + Cookie.DOMAIN_OVERBOUNDS).values().iterator();
while (iter.hasNext()) {
Cookie cookie = (Cookie) (iter.next());
Expand Down Expand Up @@ -656,7 +657,7 @@ public Cookie[] match(String host, int port, String path,
* @param list - the list to add the cookie to
* @param addCookie - the Cookie to add to list
*/
private static void addInPathOrder(List list, Cookie addCookie) {
private static void addInPathOrder(List<Cookie> list, Cookie addCookie) {
int i = 0;

for (i = 0; i < list.size(); i++) {
Expand Down
Expand Up @@ -42,7 +42,6 @@
*
* @since 3.0
*/
@SuppressWarnings("unchecked") // <- IA/HERITRIX CHANGE
public class IgnoreCookiesSpec implements CookieSpec {

/**
Expand All @@ -63,14 +62,16 @@ public Cookie[] parse(String host, int port, String path, boolean secure, String
/**
* @return <code>null</code>
*/
public Collection getValidDateFormats() {
@Override
public Collection<String> getValidDateFormats() {
return null;
}

/**
* Does nothing.
*/
public void setValidDateFormats(Collection datepatterns) {
@Override
public void setValidDateFormats(Collection<String> datepatterns) {
}

/**
Expand Down Expand Up @@ -152,8 +153,9 @@ public boolean pathMatch(final String path, final String topmostPath) {
}

// BEGIN IA/HERITRIX ADDITION
@Override
public Cookie[] match(String domain, int port, String path, boolean secure,
SortedMap cookiesMap) {
SortedMap<String, Cookie> cookiesMap) {
return new Cookie[0];
}
// END IA/HERITRIX CHANGE
Expand Down

2 comments on commit 6626b44

@gojomo
Copy link
Member

@gojomo gojomo commented on 6626b44 Oct 1, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd recommend avoiding (and possibly undoing) these sorts of changes to the 'org.apache.commons.httpclient' source files. We include these files so that we can make a few very-targeted minimal changes. There were all clearly marked as 'HERITRIX' to make it obvious where we'd diverged from the upstream source, to ease debugging or future merges/compares with material from upstream HttpClient. This wholesale housekeeping cleanup hides our substantive changes in a bunch of other diffs. (If distracting warnings are a concern, because the generation of HttpClient code we're using didn't care about those warnings, a minimal change like suppressing them for the whole file would be preferable.)

@travisfw
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes the concern was that the warnings mechanism becomes useless when there are always over a hundred. You're right the HttpClient code should not have been altered beyond suppressing the warnings.

Please sign in to comment.