Fix remaining compiler warnings

Fix remaining Java compiler warnings, mainly around missing
generics or deprecated code.

Also add the `-Werror` compiler option to ensure that any future
warnings will fail the build.

Issue: SPR-11064
This commit is contained in:
Phillip Webb
2013-11-21 18:15:09 -08:00
parent 4de3291dc7
commit 59002f2456
540 changed files with 1943 additions and 1843 deletions

View File

@@ -56,7 +56,7 @@ public class HttpEntity<T> {
/**
* The empty {@code HttpEntity}, with no body or headers.
*/
public static final HttpEntity EMPTY = new HttpEntity();
public static final HttpEntity<?> EMPTY = new HttpEntity<Object>();
private final HttpHeaders headers;

View File

@@ -36,7 +36,6 @@ import java.util.Set;
import java.util.TimeZone;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import org.springframework.util.LinkedCaseInsensitiveMap;
import org.springframework.util.MultiValueMap;
import org.springframework.util.StringUtils;

View File

@@ -16,16 +16,14 @@
package org.springframework.http.client;
import java.io.IOException;
import java.io.InputStream;
import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.util.EntityUtils;
import org.springframework.http.HttpHeaders;
import java.io.IOException;
import java.io.InputStream;
/**
* {@link ClientHttpResponse} implementation that uses
* Apache HttpComponents HttpClient to execute requests.

View File

@@ -21,19 +21,16 @@ import java.net.URI;
import java.util.List;
import java.util.Map;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.impl.client.CloseableHttpClient;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.apache.http.HttpEntity;
import org.apache.http.HttpEntityEnclosingRequest;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.entity.ByteArrayEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.protocol.HTTP;
import org.apache.http.protocol.HttpContext;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
/**
* {@link org.springframework.http.client.ClientHttpRequest} implementation that uses

View File

@@ -161,6 +161,7 @@ final class HttpComponentsStreamingClientHttpRequest extends AbstractClientHttpR
}
@Override
@Deprecated
public void consumeContent() throws IOException {
throw new UnsupportedOperationException();
}

View File

@@ -47,7 +47,7 @@ public class ByteArrayHttpMessageConverter extends AbstractHttpMessageConverter<
}
@Override
public byte[] readInternal(Class clazz, HttpInputMessage inputMessage) throws IOException {
public byte[] readInternal(Class<? extends byte[]> clazz, HttpInputMessage inputMessage) throws IOException {
long contentLength = inputMessage.getHeaders().getContentLength();
ByteArrayOutputStream bos = new ByteArrayOutputStream(contentLength >= 0 ? (int) contentLength : StreamUtils.BUFFER_SIZE);
StreamUtils.copy(inputMessage.getBody(), bos);

View File

@@ -271,7 +271,7 @@ public class FormHttpMessageConverter implements HttpMessageConverter<MultiValue
for (Object part : entry.getValue()) {
if (part != null) {
writeBoundary(boundary, os);
HttpEntity entity = getEntity(part);
HttpEntity<?> entity = getEntity(part);
writePart(name, entity, os);
writeNewLine(os);
}
@@ -286,30 +286,29 @@ public class FormHttpMessageConverter implements HttpMessageConverter<MultiValue
writeNewLine(os);
}
@SuppressWarnings("unchecked")
private HttpEntity getEntity(Object part) {
private HttpEntity<?> getEntity(Object part) {
if (part instanceof HttpEntity) {
return (HttpEntity) part;
return (HttpEntity<?>) part;
}
else {
return new HttpEntity(part);
return new HttpEntity<Object>(part);
}
}
@SuppressWarnings("unchecked")
private void writePart(String name, HttpEntity partEntity, OutputStream os) throws IOException {
private void writePart(String name, HttpEntity<?> partEntity, OutputStream os) throws IOException {
Object partBody = partEntity.getBody();
Class<?> partType = partBody.getClass();
HttpHeaders partHeaders = partEntity.getHeaders();
MediaType partContentType = partHeaders.getContentType();
for (HttpMessageConverter messageConverter : partConverters) {
for (HttpMessageConverter<?> messageConverter : partConverters) {
if (messageConverter.canWrite(partType, partContentType)) {
HttpOutputMessage multipartOutputMessage = new MultipartHttpOutputMessage(os);
multipartOutputMessage.getHeaders().setContentDispositionFormData(name, getFilename(partBody));
if (!partHeaders.isEmpty()) {
multipartOutputMessage.getHeaders().putAll(partHeaders);
}
messageConverter.write(partBody, partContentType, multipartOutputMessage);
((HttpMessageConverter<Object>) messageConverter).write(partBody, partContentType, multipartOutputMessage);
return;
}
}

View File

@@ -15,9 +15,10 @@
*/
package org.springframework.http.converter.support;
import javax.xml.transform.Source;
import org.springframework.http.converter.FormHttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.http.converter.json.MappingJacksonHttpMessageConverter;
import org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter;
import org.springframework.http.converter.xml.SourceHttpMessageConverter;
import org.springframework.util.ClassUtils;
@@ -43,8 +44,9 @@ public class AllEncompassingFormHttpMessageConverter extends FormHttpMessageConv
ClassUtils.isPresent("javax.xml.bind.Binder", AllEncompassingFormHttpMessageConverter.class.getClassLoader());
@SuppressWarnings("deprecation")
public AllEncompassingFormHttpMessageConverter() {
addPartConverter(new SourceHttpMessageConverter());
addPartConverter(new SourceHttpMessageConverter<Source>());
if (jaxb2Present) {
addPartConverter(new Jaxb2RootElementHttpMessageConverter());
}
@@ -52,7 +54,7 @@ public class AllEncompassingFormHttpMessageConverter extends FormHttpMessageConv
addPartConverter(new MappingJackson2HttpMessageConverter());
}
else if (jacksonPresent) {
addPartConverter(new MappingJacksonHttpMessageConverter());
addPartConverter(new org.springframework.http.converter.json.MappingJacksonHttpMessageConverter());
}
}

View File

@@ -35,7 +35,7 @@ import org.springframework.util.Assert;
*/
public abstract class AbstractJaxb2HttpMessageConverter<T> extends AbstractXmlHttpMessageConverter<T> {
private final ConcurrentMap<Class, JAXBContext> jaxbContexts = new ConcurrentHashMap<Class, JAXBContext>(64);
private final ConcurrentMap<Class<?>, JAXBContext> jaxbContexts = new ConcurrentHashMap<Class<?>, JAXBContext>(64);
/**
@@ -44,7 +44,7 @@ public abstract class AbstractJaxb2HttpMessageConverter<T> extends AbstractXmlHt
* @return the {@code Marshaller}
* @throws HttpMessageConversionException in case of JAXB errors
*/
protected final Marshaller createMarshaller(Class clazz) {
protected final Marshaller createMarshaller(Class<?> clazz) {
try {
JAXBContext jaxbContext = getJaxbContext(clazz);
return jaxbContext.createMarshaller();
@@ -61,7 +61,7 @@ public abstract class AbstractJaxb2HttpMessageConverter<T> extends AbstractXmlHt
* @return the {@code Unmarshaller}
* @throws HttpMessageConversionException in case of JAXB errors
*/
protected final Unmarshaller createUnmarshaller(Class clazz) throws JAXBException {
protected final Unmarshaller createUnmarshaller(Class<?> clazz) throws JAXBException {
try {
JAXBContext jaxbContext = getJaxbContext(clazz);
return jaxbContext.createUnmarshaller();
@@ -78,7 +78,7 @@ public abstract class AbstractJaxb2HttpMessageConverter<T> extends AbstractXmlHt
* @return the {@code JAXBContext}
* @throws HttpMessageConversionException in case of JAXB errors
*/
protected final JAXBContext getJaxbContext(Class clazz) {
protected final JAXBContext getJaxbContext(Class<?> clazz) {
Assert.notNull(clazz, "'clazz' must not be null");
JAXBContext jaxbContext = this.jaxbContexts.get(clazz);
if (jaxbContext == null) {

View File

@@ -54,6 +54,7 @@ import org.springframework.http.converter.HttpMessageNotReadableException;
* @author Arjen Poutsma
* @since 3.2
*/
@SuppressWarnings("rawtypes")
public class Jaxb2CollectionHttpMessageConverter<T extends Collection>
extends AbstractJaxb2HttpMessageConverter<T> implements GenericHttpMessageConverter<T> {
@@ -121,6 +122,7 @@ public class Jaxb2CollectionHttpMessageConverter<T extends Collection>
}
@Override
@SuppressWarnings("unchecked")
public T read(Type type, Class<?> contextClass, HttpInputMessage inputMessage)
throws IOException, HttpMessageNotReadableException {

View File

@@ -74,7 +74,7 @@ public class Jaxb2RootElementHttpMessageConverter extends AbstractJaxb2HttpMessa
return unmarshaller.unmarshal(source);
}
else {
JAXBElement jaxbElement = unmarshaller.unmarshal(source, clazz);
JAXBElement<?> jaxbElement = unmarshaller.unmarshal(source, clazz);
return jaxbElement.getValue();
}
}
@@ -90,7 +90,7 @@ public class Jaxb2RootElementHttpMessageConverter extends AbstractJaxb2HttpMessa
@Override
protected void writeToResult(Object o, HttpHeaders headers, Result result) throws IOException {
try {
Class clazz = ClassUtils.getUserClass(o);
Class<?> clazz = ClassUtils.getUserClass(o);
Marshaller marshaller = createMarshaller(clazz);
setCharset(headers.getContentType(), marshaller);
marshaller.marshal(o, result);

View File

@@ -20,6 +20,7 @@ import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
@@ -41,7 +42,6 @@ import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.XMLReaderFactory;
import org.springframework.http.HttpInputMessage;
import org.springframework.http.HttpOutputMessage;
import org.springframework.http.MediaType;
@@ -89,6 +89,7 @@ public class SourceHttpMessageConverter<T extends Source> extends AbstractHttpMe
}
@Override
@SuppressWarnings("unchecked")
protected T readInternal(Class<? extends T> clazz, HttpInputMessage inputMessage)
throws IOException, HttpMessageNotReadableException {

View File

@@ -16,6 +16,8 @@
package org.springframework.http.converter.xml;
import javax.xml.transform.Source;
import org.springframework.http.converter.FormHttpMessageConverter;
import org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter;
@@ -32,7 +34,7 @@ public class XmlAwareFormHttpMessageConverter extends FormHttpMessageConverter {
public XmlAwareFormHttpMessageConverter() {
super();
addPartConverter(new SourceHttpMessageConverter());
addPartConverter(new SourceHttpMessageConverter<Source>());
}
}

View File

@@ -33,8 +33,8 @@ import com.caucho.hessian.io.HessianOutput;
import com.caucho.hessian.io.HessianRemoteResolver;
import com.caucho.hessian.io.SerializerFactory;
import com.caucho.hessian.server.HessianSkeleton;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.Log;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.remoting.support.RemoteExporter;
import org.springframework.util.Assert;
@@ -155,9 +155,11 @@ public class HessianExporter extends RemoteExporter implements InitializingBean
if (this.debugLogger != null && this.debugLogger.isDebugEnabled()) {
PrintWriter debugWriter = new PrintWriter(new CommonsLogWriter(this.debugLogger));
@SuppressWarnings("resource")
HessianDebugInputStream dis = new HessianDebugInputStream(inputStream, debugWriter);
dis.startTop2();
@SuppressWarnings("resource")
HessianDebugOutputStream dos = new HessianDebugOutputStream(outputStream, debugWriter);
dis.startTop2();
dos.startTop2();
isToUse = dis;
osToUse = dos;

View File

@@ -28,15 +28,7 @@ import org.apache.http.NoHttpResponseException;
import org.apache.http.StatusLine;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.conn.scheme.PlainSocketFactory;
import org.apache.http.conn.scheme.Scheme;
import org.apache.http.conn.scheme.SchemeRegistry;
import org.apache.http.conn.ssl.SSLSocketFactory;
import org.apache.http.entity.ByteArrayEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.conn.PoolingClientConnectionManager;
import org.apache.http.params.CoreConnectionPNames;
import org.springframework.context.i18n.LocaleContext;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.remoting.support.RemoteInvocationResult;
@@ -58,6 +50,7 @@ import org.springframework.util.StringUtils;
* @since 3.1
* @see org.springframework.remoting.httpinvoker.SimpleHttpInvokerRequestExecutor
*/
@SuppressWarnings("deprecation")
public class HttpComponentsHttpInvokerRequestExecutor extends AbstractHttpInvokerRequestExecutor {
private static final int DEFAULT_MAX_TOTAL_CONNECTIONS = 100;
@@ -74,15 +67,16 @@ public class HttpComponentsHttpInvokerRequestExecutor extends AbstractHttpInvoke
* {@link HttpClient} that uses a default {@link org.apache.http.impl.conn.PoolingClientConnectionManager}.
*/
public HttpComponentsHttpInvokerRequestExecutor() {
SchemeRegistry schemeRegistry = new SchemeRegistry();
schemeRegistry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));
schemeRegistry.register(new Scheme("https", 443, SSLSocketFactory.getSocketFactory()));
org.apache.http.conn.scheme.SchemeRegistry schemeRegistry = new org.apache.http.conn.scheme.SchemeRegistry();
schemeRegistry.register(new org.apache.http.conn.scheme.Scheme("http", 80, org.apache.http.conn.scheme.PlainSocketFactory.getSocketFactory()));
schemeRegistry.register(new org.apache.http.conn.scheme.Scheme("https", 443, org.apache.http.conn.ssl.SSLSocketFactory.getSocketFactory()));
PoolingClientConnectionManager connectionManager = new PoolingClientConnectionManager(schemeRegistry);
org.apache.http.impl.conn.PoolingClientConnectionManager connectionManager =
new org.apache.http.impl.conn.PoolingClientConnectionManager(schemeRegistry);
connectionManager.setMaxTotal(DEFAULT_MAX_TOTAL_CONNECTIONS);
connectionManager.setDefaultMaxPerRoute(DEFAULT_MAX_CONNECTIONS_PER_ROUTE);
this.httpClient = new DefaultHttpClient(connectionManager);
this.httpClient = new org.apache.http.impl.client.DefaultHttpClient(connectionManager);
setReadTimeout(DEFAULT_READ_TIMEOUT_MILLISECONDS);
}
@@ -117,7 +111,7 @@ public class HttpComponentsHttpInvokerRequestExecutor extends AbstractHttpInvoke
*/
public void setConnectTimeout(int timeout) {
Assert.isTrue(timeout >= 0, "Timeout must be a non-negative value");
getHttpClient().getParams().setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, timeout);
getHttpClient().getParams().setIntParameter(org.apache.http.params.CoreConnectionPNames.CONNECTION_TIMEOUT, timeout);
}
/**
@@ -128,7 +122,7 @@ public class HttpComponentsHttpInvokerRequestExecutor extends AbstractHttpInvoke
*/
public void setReadTimeout(int timeout) {
Assert.isTrue(timeout >= 0, "Timeout must be a non-negative value");
getHttpClient().getParams().setIntParameter(CoreConnectionPNames.SO_TIMEOUT, timeout);
getHttpClient().getParams().setIntParameter(org.apache.http.params.CoreConnectionPNames.SO_TIMEOUT, timeout);
}

View File

@@ -202,7 +202,7 @@ public class EscapedErrors implements Errors {
}
@Override
public Class getFieldType(String field) {
public Class<?> getFieldType(String field) {
return this.source.getFieldType(field);
}

View File

@@ -44,8 +44,7 @@ public class UnsatisfiedServletRequestParameterException extends ServletRequestB
* @param paramConditions the parameter conditions that have been violated
* @param actualParams the actual parameter Map associated with the ServletRequest
*/
@SuppressWarnings("unchecked")
public UnsatisfiedServletRequestParameterException(String[] paramConditions, Map actualParams) {
public UnsatisfiedServletRequestParameterException(String[] paramConditions, Map<String, String[]> actualParams) {
super("");
this.paramConditions = paramConditions;
this.actualParams = actualParams;

View File

@@ -232,7 +232,7 @@ public class WebDataBinder extends DataBinder {
if (pv.getName().startsWith(fieldMarkerPrefix)) {
String field = pv.getName().substring(fieldMarkerPrefix.length());
if (getPropertyAccessor().isWritableProperty(field) && !mpvs.contains(field)) {
Class fieldType = getPropertyAccessor().getPropertyType(field);
Class<?> fieldType = getPropertyAccessor().getPropertyType(field);
mpvs.add(field, getEmptyValue(field, fieldType));
}
mpvs.removePropertyValue(pv);
@@ -250,7 +250,7 @@ public class WebDataBinder extends DataBinder {
* @param fieldType the type of the field
* @return the empty value (for most fields: null)
*/
protected Object getEmptyValue(String field, Class fieldType) {
protected Object getEmptyValue(String field, Class<?> fieldType) {
if (fieldType != null && boolean.class.equals(fieldType) || Boolean.class.equals(fieldType)) {
// Special handling of boolean property.
return Boolean.FALSE;

View File

@@ -71,6 +71,6 @@ public @interface SessionAttributes {
* session or some conversational storage. All model attributes of this
* type will be stored in the session, regardless of attribute name.
*/
Class[] types() default {};
Class<?>[] types() default {};
}

View File

@@ -34,7 +34,6 @@ import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.BridgeMethodResolver;
@@ -110,7 +109,7 @@ public class HandlerMethodInvoker {
private final WebArgumentResolver[] customArgumentResolvers;
private final HttpMessageConverter[] messageConverters;
private final HttpMessageConverter<?>[] messageConverters;
private final SimpleSessionStatus sessionStatus = new SimpleSessionStatus();
@@ -125,7 +124,7 @@ public class HandlerMethodInvoker {
public HandlerMethodInvoker(HandlerMethodResolver methodResolver, WebBindingInitializer bindingInitializer,
SessionAttributeStore sessionAttributeStore, ParameterNameDiscoverer parameterNameDiscoverer,
WebArgumentResolver[] customArgumentResolvers, HttpMessageConverter[] messageConverters) {
WebArgumentResolver[] customArgumentResolvers, HttpMessageConverter<?>[] messageConverters) {
this.methodResolver = methodResolver;
this.bindingInitializer = bindingInitializer;
@@ -161,7 +160,7 @@ public class HandlerMethodInvoker {
ReflectionUtils.makeAccessible(attributeMethodToInvoke);
Object attrValue = attributeMethodToInvoke.invoke(handler, args);
if ("".equals(attrName)) {
Class resolvedType = GenericTypeResolver.resolveReturnType(attributeMethodToInvoke, handler.getClass());
Class<?> resolvedType = GenericTypeResolver.resolveReturnType(attributeMethodToInvoke, handler.getClass());
attrName = Conventions.getVariableNameForReturnType(attributeMethodToInvoke, resolvedType, attrValue);
}
if (!implicitModel.containsAttribute(attrName)) {
@@ -236,7 +235,7 @@ public class HandlerMethodInvoker {
private Object[] resolveHandlerArguments(Method handlerMethod, Object handler,
NativeWebRequest webRequest, ExtendedModelMap implicitModel) throws Exception {
Class[] paramTypes = handlerMethod.getParameterTypes();
Class<?>[] paramTypes = handlerMethod.getParameterTypes();
Object[] args = new Object[paramTypes.length];
for (int i = 0; i < args.length; i++) {
@@ -412,7 +411,7 @@ public class HandlerMethodInvoker {
private Object[] resolveInitBinderArguments(Object handler, Method initBinderMethod,
WebDataBinder binder, NativeWebRequest webRequest) throws Exception {
Class[] initBinderParams = initBinderMethod.getParameterTypes();
Class<?>[] initBinderParams = initBinderMethod.getParameterTypes();
Object[] initBinderArgs = new Object[initBinderParams.length];
for (int i = 0; i < initBinderArgs.length; i++) {
@@ -449,7 +448,7 @@ public class HandlerMethodInvoker {
initBinderArgs[i] = argValue;
}
else {
Class paramType = initBinderParams[i];
Class<?> paramType = initBinderParams[i];
if (paramType.isInstance(binder)) {
initBinderArgs[i] = binder;
}
@@ -482,7 +481,7 @@ public class HandlerMethodInvoker {
Class<?> paramType = methodParam.getParameterType();
if (Map.class.isAssignableFrom(paramType) && paramName.length() == 0) {
return resolveRequestParamMap((Class<? extends Map>) paramType, webRequest);
return resolveRequestParamMap((Class<? extends Map<?, ?>>) paramType, webRequest);
}
if (paramName.length() == 0) {
paramName = getRequiredParameterName(methodParam);
@@ -515,7 +514,7 @@ public class HandlerMethodInvoker {
return binder.convertIfNecessary(paramValue, paramType, methodParam);
}
private Map resolveRequestParamMap(Class<? extends Map> mapType, NativeWebRequest webRequest) {
private Map<String, ?> resolveRequestParamMap(Class<? extends Map<?, ?>> mapType, NativeWebRequest webRequest) {
Map<String, String[]> parameterMap = webRequest.getParameterMap();
if (MultiValueMap.class.isAssignableFrom(mapType)) {
MultiValueMap<String, String> result = new LinkedMultiValueMap<String, String>(parameterMap.size());
@@ -544,7 +543,7 @@ public class HandlerMethodInvoker {
Class<?> paramType = methodParam.getParameterType();
if (Map.class.isAssignableFrom(paramType)) {
return resolveRequestHeaderMap((Class<? extends Map>) paramType, webRequest);
return resolveRequestHeaderMap((Class<? extends Map<?, ?>>) paramType, webRequest);
}
if (headerName.length() == 0) {
headerName = getRequiredParameterName(methodParam);
@@ -568,7 +567,7 @@ public class HandlerMethodInvoker {
return binder.convertIfNecessary(headerValue, paramType, methodParam);
}
private Map resolveRequestHeaderMap(Class<? extends Map> mapType, NativeWebRequest webRequest) {
private Map<String, ?> resolveRequestHeaderMap(Class<? extends Map<?, ?>> mapType, NativeWebRequest webRequest) {
if (MultiValueMap.class.isAssignableFrom(mapType)) {
MultiValueMap<String, String> result;
if (HttpHeaders.class.isAssignableFrom(mapType)) {
@@ -605,7 +604,7 @@ public class HandlerMethodInvoker {
return readWithMessageConverters(methodParam, createHttpInputMessage(webRequest), methodParam.getParameterType());
}
private HttpEntity resolveHttpEntityRequest(MethodParameter methodParam, NativeWebRequest webRequest)
private HttpEntity<?> resolveHttpEntityRequest(MethodParameter methodParam, NativeWebRequest webRequest)
throws Exception {
HttpInputMessage inputMessage = createHttpInputMessage(webRequest);
@@ -614,7 +613,8 @@ public class HandlerMethodInvoker {
return new HttpEntity<Object>(body, inputMessage.getHeaders());
}
private Object readWithMessageConverters(MethodParameter methodParam, HttpInputMessage inputMessage, Class paramType)
@SuppressWarnings({ "unchecked", "rawtypes" })
private Object readWithMessageConverters(MethodParameter methodParam, HttpInputMessage inputMessage, Class<?> paramType)
throws Exception {
MediaType contentType = inputMessage.getHeaders().getContentType();
@@ -638,7 +638,7 @@ public class HandlerMethodInvoker {
logger.debug("Reading [" + paramType.getName() + "] as \"" + contentType
+"\" using [" + messageConverter + "]");
}
return messageConverter.read(paramType, inputMessage);
return messageConverter.read((Class) paramType, inputMessage);
}
}
}
@@ -694,7 +694,7 @@ public class HandlerMethodInvoker {
* Resolves the given {@link CookieValue @CookieValue} annotation.
* <p>Throws an UnsupportedOperationException by default.
*/
protected Object resolveCookieValue(String cookieName, Class paramType, NativeWebRequest webRequest)
protected Object resolveCookieValue(String cookieName, Class<?> paramType, NativeWebRequest webRequest)
throws Exception {
throw new UnsupportedOperationException("@CookieValue not supported");
@@ -717,7 +717,7 @@ public class HandlerMethodInvoker {
* Resolves the given {@link PathVariable @PathVariable} annotation.
* <p>Throws an UnsupportedOperationException by default.
*/
protected String resolvePathVariable(String pathVarName, Class paramType, NativeWebRequest webRequest)
protected String resolvePathVariable(String pathVarName, Class<?> paramType, NativeWebRequest webRequest)
throws Exception {
throw new UnsupportedOperationException("@PathVariable not supported");
@@ -733,7 +733,7 @@ public class HandlerMethodInvoker {
return name;
}
private Object checkValue(String name, Object value, Class paramType) {
private Object checkValue(String name, Object value, Class<?> paramType) {
if (value == null) {
if (boolean.class.equals(paramType)) {
return Boolean.FALSE;
@@ -784,15 +784,15 @@ public class HandlerMethodInvoker {
!(value instanceof Map) && !BeanUtils.isSimpleValueType(value.getClass()));
}
protected void raiseMissingParameterException(String paramName, Class paramType) throws Exception {
protected void raiseMissingParameterException(String paramName, Class<?> paramType) throws Exception {
throw new IllegalStateException("Missing parameter '" + paramName + "' of type [" + paramType.getName() + "]");
}
protected void raiseMissingHeaderException(String headerName, Class paramType) throws Exception {
protected void raiseMissingHeaderException(String headerName, Class<?> paramType) throws Exception {
throw new IllegalStateException("Missing header '" + headerName + "' of type [" + paramType.getName() + "]");
}
protected void raiseMissingCookieException(String cookieName, Class paramType) throws Exception {
protected void raiseMissingCookieException(String cookieName, Class<?> paramType) throws Exception {
throw new IllegalStateException(
"Missing cookie value '" + cookieName + "' of type [" + paramType.getName() + "]");
}
@@ -861,7 +861,7 @@ public class HandlerMethodInvoker {
}
// Resolution of standard parameter types...
Class paramType = methodParameter.getParameterType();
Class<?> paramType = methodParameter.getParameterType();
Object value = resolveStandardArgument(paramType, webRequest);
if (value != WebArgumentResolver.UNRESOLVED && !ClassUtils.isAssignableValue(paramType, value)) {
throw new IllegalStateException("Standard argument type [" + paramType.getName() +
@@ -878,13 +878,13 @@ public class HandlerMethodInvoker {
return WebArgumentResolver.UNRESOLVED;
}
protected final void addReturnValueAsModelAttribute(Method handlerMethod, Class handlerType,
protected final void addReturnValueAsModelAttribute(Method handlerMethod, Class<?> handlerType,
Object returnValue, ExtendedModelMap implicitModel) {
ModelAttribute attr = AnnotationUtils.findAnnotation(handlerMethod, ModelAttribute.class);
String attrName = (attr != null ? attr.value() : "");
if ("".equals(attrName)) {
Class resolvedType = GenericTypeResolver.resolveReturnType(handlerMethod, handlerType);
Class<?> resolvedType = GenericTypeResolver.resolveReturnType(handlerMethod, handlerType);
attrName = Conventions.getVariableNameForReturnType(handlerMethod, resolvedType, returnValue);
}
implicitModel.addAttribute(attrName, returnValue);

View File

@@ -63,7 +63,7 @@ public class HandlerMethodResolver {
private final Set<String> sessionAttributeNames = new HashSet<String>();
private final Set<Class> sessionAttributeTypes = new HashSet<Class>();
private final Set<Class<?>> sessionAttributeTypes = new HashSet<Class<?>>();
private final Set<String> actualSessionAttributeNames =
Collections.newSetFromMap(new ConcurrentHashMap<String, Boolean>(4));
@@ -153,7 +153,7 @@ public class HandlerMethodResolver {
return this.sessionAttributesFound;
}
public boolean isSessionAttribute(String attrName, Class attrType) {
public boolean isSessionAttribute(String attrName, Class<?> attrType) {
if (this.sessionAttributeNames.contains(attrName) || this.sessionAttributeTypes.contains(attrType)) {
this.actualSessionAttributeNames.add(attrName);
return true;

View File

@@ -542,7 +542,6 @@ public class AsyncRestTemplate extends AsyncHttpAccessor implements AsyncRestOpe
* be {@code null})
* @return an arbitrary object, as returned by the {@link ResponseExtractor}
*/
@SuppressWarnings("unchecked")
protected <T> ListenableFuture<T> doExecute(URI url, HttpMethod method, AsyncRequestCallback requestCallback,
ResponseExtractor<T> responseExtractor) throws RestClientException {

View File

@@ -77,16 +77,16 @@ public class HttpMessageConverterExtractor<T> implements ResponseExtractor<T> {
}
@Override
@SuppressWarnings("unchecked")
@SuppressWarnings({ "unchecked", "rawtypes" })
public T extractData(ClientHttpResponse response) throws IOException {
if (!hasMessageBody(response)) {
return null;
}
MediaType contentType = getContentType(response);
for (HttpMessageConverter messageConverter : this.messageConverters) {
for (HttpMessageConverter<?> messageConverter : this.messageConverters) {
if (messageConverter instanceof GenericHttpMessageConverter) {
GenericHttpMessageConverter genericMessageConverter = (GenericHttpMessageConverter) messageConverter;
GenericHttpMessageConverter<?> genericMessageConverter = (GenericHttpMessageConverter<?>) messageConverter;
if (genericMessageConverter.canRead(this.responseType, null, contentType)) {
if (logger.isDebugEnabled()) {
logger.debug("Reading [" + this.responseType + "] as \"" +
@@ -101,7 +101,7 @@ public class HttpMessageConverterExtractor<T> implements ResponseExtractor<T> {
logger.debug("Reading [" + this.responseClass.getName() + "] as \"" +
contentType + "\" using [" + messageConverter + "]");
}
return (T) messageConverter.read(this.responseClass, response);
return (T) messageConverter.read((Class) this.responseClass, response);
}
}
}

View File

@@ -24,6 +24,8 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.xml.transform.Source;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
@@ -42,7 +44,6 @@ import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.http.converter.feed.AtomFeedHttpMessageConverter;
import org.springframework.http.converter.feed.RssChannelHttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.http.converter.json.MappingJacksonHttpMessageConverter;
import org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter;
import org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter;
import org.springframework.http.converter.xml.SourceHttpMessageConverter;
@@ -148,11 +149,12 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat
/**
* Create a new instance of the {@link RestTemplate} using default settings.
*/
@SuppressWarnings("deprecation")
public RestTemplate() {
this.messageConverters.add(new ByteArrayHttpMessageConverter());
this.messageConverters.add(new StringHttpMessageConverter());
this.messageConverters.add(new ResourceHttpMessageConverter());
this.messageConverters.add(new SourceHttpMessageConverter());
this.messageConverters.add(new SourceHttpMessageConverter<Source>());
this.messageConverters.add(new AllEncompassingFormHttpMessageConverter());
if (romePresent) {
this.messageConverters.add(new AtomFeedHttpMessageConverter());
@@ -165,7 +167,7 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat
this.messageConverters.add(new MappingJackson2HttpMessageConverter());
}
else if (jacksonPresent) {
this.messageConverters.add(new MappingJacksonHttpMessageConverter());
this.messageConverters.add(new org.springframework.http.converter.json.MappingJacksonHttpMessageConverter());
}
}
@@ -604,7 +606,7 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat
* Returns a response extractor for {@link ResponseEntity}.
*/
protected <T> ResponseExtractor<ResponseEntity<T>> responseEntityExtractor(Type responseType) {
return new ResponseEntityResponseExtractor(responseType);
return new ResponseEntityResponseExtractor<T>(responseType);
}
/**
@@ -627,12 +629,11 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat
}
@Override
@SuppressWarnings("unchecked")
public void doWithRequest(ClientHttpRequest request) throws IOException {
if (responseType != null) {
Class<?> responseClass = null;
if (responseType instanceof Class) {
responseClass = (Class) responseType;
responseClass = (Class<?>) responseType;
}
List<MediaType> allSupportedMediaTypes = new ArrayList<MediaType>();
@@ -644,7 +645,7 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat
}
else if (converter instanceof GenericHttpMessageConverter) {
GenericHttpMessageConverter genericConverter = (GenericHttpMessageConverter) converter;
GenericHttpMessageConverter<?> genericConverter = (GenericHttpMessageConverter<?>) converter;
if (genericConverter.canRead(responseType, null, null)) {
allSupportedMediaTypes.addAll(getSupportedMediaTypes(converter));
}
@@ -682,20 +683,19 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat
*/
private class HttpEntityRequestCallback extends AcceptHeaderRequestCallback {
private final HttpEntity requestEntity;
private final HttpEntity<?> requestEntity;
private HttpEntityRequestCallback(Object requestBody) {
this(requestBody, null);
}
@SuppressWarnings("unchecked")
private HttpEntityRequestCallback(Object requestBody, Type responseType) {
super(responseType);
if (requestBody instanceof HttpEntity) {
this.requestEntity = (HttpEntity) requestBody;
this.requestEntity = (HttpEntity<?>) requestBody;
}
else if (requestBody != null) {
this.requestEntity = new HttpEntity(requestBody);
this.requestEntity = new HttpEntity<Object>(requestBody);
}
else {
this.requestEntity = HttpEntity.EMPTY;
@@ -721,7 +721,7 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat
Class<?> requestType = requestBody.getClass();
HttpHeaders requestHeaders = requestEntity.getHeaders();
MediaType requestContentType = requestHeaders.getContentType();
for (HttpMessageConverter messageConverter : getMessageConverters()) {
for (HttpMessageConverter<?> messageConverter : getMessageConverters()) {
if (messageConverter.canWrite(requestType, requestContentType)) {
if (!requestHeaders.isEmpty()) {
httpRequest.getHeaders().putAll(requestHeaders);
@@ -736,7 +736,8 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat
}
}
messageConverter.write(requestBody, requestContentType, httpRequest);
((HttpMessageConverter<Object>) messageConverter).write(
requestBody, requestContentType, httpRequest);
return;
}
}

View File

@@ -59,9 +59,9 @@ public class ContextCleanupListener implements ServletContextListener {
* @param sc the ServletContext to check
*/
static void cleanupAttributes(ServletContext sc) {
Enumeration attrNames = sc.getAttributeNames();
Enumeration<String> attrNames = sc.getAttributeNames();
while (attrNames.hasMoreElements()) {
String attrName = (String) attrNames.nextElement();
String attrName = attrNames.nextElement();
if (attrName.startsWith("org.springframework.")) {
Object attrValue = sc.getAttribute(attrName);
if (attrValue instanceof DisposableBean) {

View File

@@ -37,7 +37,7 @@ import org.springframework.beans.factory.config.Scope;
public abstract class AbstractRequestAttributesScope implements Scope {
@Override
public Object get(String name, ObjectFactory objectFactory) {
public Object get(String name, ObjectFactory<?> objectFactory) {
RequestAttributes attributes = RequestContextHolder.currentRequestAttributes();
Object scopedObject = attributes.getAttribute(name, getScope());
if (scopedObject == null) {

View File

@@ -217,7 +217,7 @@ public class FacesRequestAttributes implements RequestAttributes {
Object session = getExternalContext().getSession(true);
try {
// Both HttpSession and PortletSession have a getId() method.
Method getIdMethod = session.getClass().getMethod("getId", new Class[0]);
Method getIdMethod = session.getClass().getMethod("getId", new Class<?>[0]);
return ReflectionUtils.invokeMethod(getIdMethod, session).toString();
}
catch (NoSuchMethodException ex) {

View File

@@ -87,7 +87,7 @@ public class SessionScope extends AbstractRequestAttributesScope {
}
@Override
public Object get(String name, ObjectFactory objectFactory) {
public Object get(String name, ObjectFactory<?> objectFactory) {
Object mutex = RequestContextHolder.currentRequestAttributes().getSessionMutex();
synchronized (mutex) {
return super.get(name, objectFactory);

View File

@@ -253,7 +253,7 @@ public final class WebAsyncManager {
* @see #getConcurrentResult()
* @see #getConcurrentResultContext()
*/
@SuppressWarnings({"unchecked" })
@SuppressWarnings({"unchecked", "rawtypes" })
public void startCallableProcessing(final Callable<?> callable, Object... processingContext) throws Exception {
Assert.notNull(callable, "Callable must not be null");
startCallableProcessing(new WebAsyncTask(callable), processingContext);

View File

@@ -160,15 +160,20 @@ public class ServletContextResourcePatternResolver extends PathMatchingResourceP
}
try {
JarFile jarFile = new JarFile(jarFilePath);
for (Enumeration<JarEntry> entries = jarFile.entries(); entries.hasMoreElements();) {
JarEntry entry = entries.nextElement();
String entryPath = entry.getName();
if (getPathMatcher().match(entryPattern, entryPath)) {
result.add(new UrlResource(
ResourceUtils.URL_PROTOCOL_JAR,
ResourceUtils.FILE_URL_PREFIX + jarFilePath + ResourceUtils.JAR_URL_SEPARATOR + entryPath));
try {
for (Enumeration<JarEntry> entries = jarFile.entries(); entries.hasMoreElements();) {
JarEntry entry = entries.nextElement();
String entryPath = entry.getName();
if (getPathMatcher().match(entryPattern, entryPath)) {
result.add(new UrlResource(
ResourceUtils.URL_PROTOCOL_JAR,
ResourceUtils.FILE_URL_PREFIX + jarFilePath + ResourceUtils.JAR_URL_SEPARATOR + entryPath));
}
}
}
finally {
jarFile.close();
}
}
catch (IOException ex) {
if (logger.isWarnEnabled()) {

View File

@@ -172,7 +172,7 @@ public class RequestParamMethodArgumentResolver extends AbstractNamedValueMethod
}
else if (isPartCollection(parameter)) {
assertIsMultipartRequest(servletRequest);
arg = new ArrayList(servletRequest.getParts());
arg = new ArrayList<Object>(servletRequest.getParts());
}
else {
arg = null;
@@ -243,7 +243,7 @@ public class RequestParamMethodArgumentResolver extends AbstractNamedValueMethod
builder.queryParam(name);
}
else if (value instanceof Collection) {
for (Object v : (Collection) value) {
for (Object v : (Collection<?>) value) {
v = formatUriValue(conversionService, TypeDescriptor.nested(parameter, 1), v);
builder.queryParam(name, v);
}

View File

@@ -151,7 +151,6 @@ public class CommonsMultipartResolver extends CommonsFileUploadSupport
* @return the parsing result
* @throws MultipartException if multipart resolution failed.
*/
@SuppressWarnings("unchecked")
protected MultipartParsingResult parseRequest(HttpServletRequest request) throws MultipartException {
String encoding = determineEncoding(request);
FileUpload fileUpload = prepareFileUpload(encoding);

View File

@@ -76,9 +76,9 @@ public class DefaultMultipartHttpServletRequest extends AbstractMultipartHttpSer
@Override
public Enumeration<String> getParameterNames() {
Set<String> paramNames = new HashSet<String>();
Enumeration paramEnum = super.getParameterNames();
Enumeration<String> paramEnum = super.getParameterNames();
while (paramEnum.hasMoreElements()) {
paramNames.add((String) paramEnum.nextElement());
paramNames.add(paramEnum.nextElement());
}
paramNames.addAll(getMultipartParameters().keySet());
return Collections.enumeration(paramNames);

View File

@@ -82,7 +82,7 @@ class HtmlCharacterEntityReferences {
}
// Parse reference definition properties
Enumeration keys = entityReferences.propertyNames();
Enumeration<?> keys = entityReferences.propertyNames();
while (keys.hasMoreElements()) {
String key = (String) keys.nextElement();
int referredChar = Integer.parseInt(key);

View File

@@ -92,7 +92,7 @@ public abstract class TagUtils {
* or if the supplied {@code ancestorTagClass} is not type-assignable to
* the {@link Tag} class
*/
public static boolean hasAncestorOfType(Tag tag, Class ancestorTagClass) {
public static boolean hasAncestorOfType(Tag tag, Class<?> ancestorTagClass) {
Assert.notNull(tag, "Tag cannot be null");
Assert.notNull(ancestorTagClass, "Ancestor tag class cannot be null");
if (!Tag.class.isAssignableFrom(ancestorTagClass)) {
@@ -125,7 +125,7 @@ public abstract class TagUtils {
* type-assignable to the {@link Tag} class
* @see #hasAncestorOfType(javax.servlet.jsp.tagext.Tag, Class)
*/
public static void assertHasAncestorOfType(Tag tag, Class ancestorTagClass, String tagName, String ancestorTagName) {
public static void assertHasAncestorOfType(Tag tag, Class<?> ancestorTagClass, String tagName, String ancestorTagName) {
Assert.hasText(tagName, "'tagName' must not be empty");
Assert.hasText(ancestorTagName, "'ancestorTagName' must not be empty");
if (!TagUtils.hasAncestorOfType(tag, ancestorTagClass)) {

View File

@@ -39,6 +39,7 @@ import org.springframework.util.MultiValueMap;
* @since 3.1
* @see UriComponentsBuilder
*/
@SuppressWarnings("serial")
public abstract class UriComponents implements Serializable {
private static final String DEFAULT_ENCODING = "UTF-8";

View File

@@ -17,9 +17,7 @@
package org.springframework.web.util;
import java.io.Serializable;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.LinkedList;

View File

@@ -317,7 +317,7 @@ public abstract class WebUtils {
* @return the value of the session attribute, newly created if not found
* @throws IllegalArgumentException if the session attribute could not be instantiated
*/
public static Object getOrCreateSessionAttribute(HttpSession session, String name, Class clazz)
public static Object getOrCreateSessionAttribute(HttpSession session, String name, Class<?> clazz)
throws IllegalArgumentException {
Assert.notNull(session, "Session must not be null");
@@ -620,13 +620,13 @@ public abstract class WebUtils {
*/
public static Map<String, Object> getParametersStartingWith(ServletRequest request, String prefix) {
Assert.notNull(request, "Request must not be null");
Enumeration paramNames = request.getParameterNames();
Enumeration<String> paramNames = request.getParameterNames();
Map<String, Object> params = new TreeMap<String, Object>();
if (prefix == null) {
prefix = "";
}
while (paramNames != null && paramNames.hasMoreElements()) {
String paramName = (String) paramNames.nextElement();
String paramName = paramNames.nextElement();
if ("".equals(prefix) || paramName.startsWith(prefix)) {
String unprefixed = paramName.substring(prefix.length());
String[] values = request.getParameterValues(paramName);
@@ -654,9 +654,9 @@ public abstract class WebUtils {
* @return the page specified in the request, or current page if not found
*/
public static int getTargetPage(ServletRequest request, String paramPrefix, int currentPage) {
Enumeration paramNames = request.getParameterNames();
Enumeration<String> paramNames = request.getParameterNames();
while (paramNames.hasMoreElements()) {
String paramName = (String) paramNames.nextElement();
String paramName = paramNames.nextElement();
if (paramName.startsWith(paramPrefix)) {
for (int i = 0; i < WebUtils.SUBMIT_IMAGE_SUFFIXES.length; i++) {
String suffix = WebUtils.SUBMIT_IMAGE_SUFFIXES[i];