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

@@ -577,7 +577,7 @@ public class DispatcherPortlet extends FrameworkPortlet {
List<T> strategies = new ArrayList<T>(classNames.length);
for (String className : classNames) {
try {
Class clazz = ClassUtils.forName(className, DispatcherPortlet.class.getClassLoader());
Class<?> clazz = ClassUtils.forName(className, DispatcherPortlet.class.getClassLoader());
Object strategy = createDefaultStrategy(context, clazz);
strategies.add((T) strategy);
}
@@ -1143,7 +1143,7 @@ public class DispatcherPortlet extends FrameworkPortlet {
* (typically in case of problems creating an actual View object)
* @see ViewResolver#resolveViewName
*/
protected View resolveViewName(String viewName, Map model, PortletRequest request) throws Exception {
protected View resolveViewName(String viewName, Map<String, ?> model, PortletRequest request) throws Exception {
for (ViewResolver viewResolver : this.viewResolvers) {
View view = viewResolver.resolveViewName(viewName, request.getLocale());
if (view != null) {
@@ -1163,7 +1163,7 @@ public class DispatcherPortlet extends FrameworkPortlet {
* @param response current portlet render/resource response
* @throws Exception if there's a problem rendering the view
*/
protected void doRender(View view, Map model, PortletRequest request, MimeResponse response) throws Exception {
protected void doRender(View view, Map<String, ?> model, PortletRequest request, MimeResponse response) throws Exception {
// Expose Portlet ApplicationContext to view objects.
request.setAttribute(ViewRendererServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, getPortletApplicationContext());

View File

@@ -107,7 +107,7 @@ public abstract class FrameworkPortlet extends GenericPortletBean
* Default context class for FrameworkPortlet.
* @see org.springframework.web.portlet.context.XmlPortletApplicationContext
*/
public static final Class DEFAULT_CONTEXT_CLASS = XmlPortletApplicationContext.class;
public static final Class<?> DEFAULT_CONTEXT_CLASS = XmlPortletApplicationContext.class;
/**
* Suffix for Portlet ApplicationContext namespaces. If a portlet of this class is
@@ -130,7 +130,7 @@ public abstract class FrameworkPortlet extends GenericPortletBean
/** Portlet ApplicationContext implementation class to use */
private Class contextClass = DEFAULT_CONTEXT_CLASS;
private Class<?> contextClass = DEFAULT_CONTEXT_CLASS;
/** Namespace for this portlet */
private String namespace;
@@ -163,14 +163,14 @@ public abstract class FrameworkPortlet extends GenericPortletBean
* must also implement ConfigurablePortletApplicationContext.
* @see #createPortletApplicationContext
*/
public void setContextClass(Class contextClass) {
public void setContextClass(Class<?> contextClass) {
this.contextClass = contextClass;
}
/**
* Return the custom context class.
*/
public Class getContextClass() {
public Class<?> getContextClass() {
return this.contextClass;
}
@@ -612,7 +612,7 @@ public abstract class FrameworkPortlet extends GenericPortletBean
}
// Try the Portlet USER_INFO map.
Map userInfo = (Map) request.getAttribute(PortletRequest.USER_INFO);
Map<?, ?> userInfo = (Map<?, ?>) request.getAttribute(PortletRequest.USER_INFO);
if (userInfo != null) {
for (int i = 0, n = this.userinfoUsernameAttributes.length; i < n; i++) {
userName = (String) userInfo.get(this.userinfoUsernameAttributes[i]);

View File

@@ -221,9 +221,9 @@ public abstract class GenericPortletBean extends GenericPortlet
Set<String> missingProps = (requiredProperties != null && !requiredProperties.isEmpty()) ?
new HashSet<String>(requiredProperties) : null;
Enumeration en = config.getInitParameterNames();
Enumeration<String> en = config.getInitParameterNames();
while (en.hasMoreElements()) {
String property = (String) en.nextElement();
String property = en.nextElement();
Object value = config.getInitParameter(property);
addPropertyValue(new PropertyValue(property, value));
if (missingProps != null) {

View File

@@ -156,16 +156,16 @@ public abstract class PortletApplicationContextUtils {
if (!bf.containsBean(WebApplicationContext.CONTEXT_PARAMETERS_BEAN_NAME)) {
Map<String, String> parameterMap = new HashMap<String, String>();
if (pc != null) {
Enumeration paramNameEnum = pc.getInitParameterNames();
Enumeration<String> paramNameEnum = pc.getInitParameterNames();
while (paramNameEnum.hasMoreElements()) {
String paramName = (String) paramNameEnum.nextElement();
String paramName = paramNameEnum.nextElement();
parameterMap.put(paramName, pc.getInitParameter(paramName));
}
}
if (config != null) {
Enumeration paramNameEnum = config.getInitParameterNames();
Enumeration<String> paramNameEnum = config.getInitParameterNames();
while (paramNameEnum.hasMoreElements()) {
String paramName = (String) paramNameEnum.nextElement();
String paramName = paramNameEnum.nextElement();
parameterMap.put(paramName, config.getInitParameter(paramName));
}
}
@@ -176,9 +176,9 @@ public abstract class PortletApplicationContextUtils {
if (!bf.containsBean(WebApplicationContext.CONTEXT_ATTRIBUTES_BEAN_NAME)) {
Map<String, Object> attributeMap = new HashMap<String, Object>();
if (pc != null) {
Enumeration attrNameEnum = pc.getAttributeNames();
Enumeration<String> attrNameEnum = pc.getAttributeNames();
while (attrNameEnum.hasMoreElements()) {
String attrName = (String) attrNameEnum.nextElement();
String attrName = attrNameEnum.nextElement();
attributeMap.put(attrName, pc.getAttribute(attrName));
}
}

View File

@@ -100,11 +100,11 @@ public class PortletContextResourcePatternResolver extends PathMatchingResourceP
protected void doRetrieveMatchingPortletContextResources(
PortletContext portletContext, String fullPattern, String dir, Set<Resource> result) throws IOException {
Set candidates = portletContext.getResourcePaths(dir);
Set<String> candidates = portletContext.getResourcePaths(dir);
if (candidates != null) {
boolean dirDepthNotFixed = fullPattern.contains("**");
for (Iterator it = candidates.iterator(); it.hasNext();) {
String currPath = (String) it.next();
for (Iterator<String> it = candidates.iterator(); it.hasNext();) {
String currPath = it.next();
if (currPath.endsWith("/") &&
(dirDepthNotFixed ||
StringUtils.countOccurrencesOf(currPath, "/") <= StringUtils.countOccurrencesOf(fullPattern, "/"))) {

View File

@@ -79,13 +79,11 @@ public class PortletWebRequest extends PortletRequestAttributes implements Nativ
}
@Override
@SuppressWarnings("unchecked")
public <T> T getNativeRequest(Class<T> requiredType) {
return PortletUtils.getNativeRequest(getRequest(), requiredType);
}
@Override
@SuppressWarnings("unchecked")
public <T> T getNativeResponse(Class<T> requiredType) {
return PortletUtils.getNativeResponse(getResponse(), requiredType);
}

View File

@@ -50,7 +50,7 @@ public abstract class AbstractHandlerExceptionResolver implements HandlerExcepti
private Set<?> mappedHandlers;
private Class[] mappedHandlerClasses;
private Class<?>[] mappedHandlerClasses;
private Log warnLogger;
@@ -90,7 +90,7 @@ public abstract class AbstractHandlerExceptionResolver implements HandlerExcepti
* any further HandlerExceptionResolvers in the chain will be ignored in
* this case.
*/
public void setMappedHandlerClasses(Class[] mappedHandlerClasses) {
public void setMappedHandlerClasses(Class<?>[] mappedHandlerClasses) {
this.mappedHandlerClasses = mappedHandlerClasses;
}
@@ -169,7 +169,7 @@ public abstract class AbstractHandlerExceptionResolver implements HandlerExcepti
return true;
}
if (this.mappedHandlerClasses != null) {
for (Class mappedClass : this.mappedHandlerClasses) {
for (Class<?> mappedClass : this.mappedHandlerClasses) {
if (mappedClass.isInstance(handler)) {
return true;
}

View File

@@ -140,7 +140,7 @@ public abstract class AbstractHandlerMapping extends ApplicationObjectSupport im
* allowing to add further interceptors before as well as after the existing
* interceptors
*/
protected void extendInterceptors(List interceptors) {
protected void extendInterceptors(List<?> interceptors) {
}
/**

View File

@@ -185,7 +185,7 @@ public abstract class AbstractMapBasedHandlerMapping<K> extends AbstractHandlerM
/**
* Predicate interface for determining a match with a given request.
*/
protected interface PortletRequestMappingPredicate extends Comparable {
protected interface PortletRequestMappingPredicate extends Comparable<PortletRequestMappingPredicate> {
/**
* Determine whether the given request matches this predicate.

View File

@@ -156,7 +156,7 @@ public class SimpleMappingExceptionResolver extends AbstractHandlerExceptionReso
String viewName = null;
String dominantMapping = null;
int deepest = Integer.MAX_VALUE;
for (Enumeration names = exceptionMappings.propertyNames(); names.hasMoreElements();) {
for (Enumeration<?> names = exceptionMappings.propertyNames(); names.hasMoreElements();) {
String exceptionMapping = (String) names.nextElement();
int depth = getDepth(exceptionMapping, ex);
if (depth >= 0 && (depth < deepest || (depth == deepest &&
@@ -184,7 +184,7 @@ public class SimpleMappingExceptionResolver extends AbstractHandlerExceptionReso
return getDepth(exceptionMapping, ex.getClass(), 0);
}
private int getDepth(String exceptionMapping, Class exceptionClass, int depth) {
private int getDepth(String exceptionMapping, Class<?> exceptionClass, int depth) {
if (exceptionClass.getName().contains(exceptionMapping)) {
// Found it!
return depth;

View File

@@ -109,9 +109,9 @@ public class DefaultMultipartActionRequest extends ActionRequestWrapper implemen
@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

@@ -89,7 +89,7 @@ public class PortletWrappingController extends AbstractController
private PortletConfig portletConfig;
private Class portletClass;
private Class<?> portletClass;
private String portletName;
@@ -127,7 +127,7 @@ public class PortletWrappingController extends AbstractController
* Needs to implement {@code javax.portlet.Portlet}.
* @see javax.portlet.Portlet
*/
public void setPortletClass(Class portletClass) {
public void setPortletClass(Class<?> portletClass) {
this.portletClass = portletClass;
}

View File

@@ -381,7 +381,7 @@ public class AnnotationMethodHandlerAdapter extends PortletContentGenerator
if (response instanceof EventResponse) {
// Update the existing model, if any, when responding to an event -
// whereas we're replacing the model in case of an action response.
Map existingModel = (Map) request.getPortletSession().getAttribute(IMPLICIT_MODEL_SESSION_ATTRIBUTE);
Map<String, Object> existingModel = (Map<String, Object>) request.getPortletSession().getAttribute(IMPLICIT_MODEL_SESSION_ATTRIBUTE);
if (existingModel != null) {
existingModel.putAll(implicitModel);
modelToStore = existingModel;
@@ -401,7 +401,7 @@ public class AnnotationMethodHandlerAdapter extends PortletContentGenerator
* Build a HandlerMethodResolver for the given handler type.
*/
private PortletHandlerMethodResolver getMethodResolver(Object handler) {
Class handlerClass = ClassUtils.getUserClass(handler);
Class<?> handlerClass = ClassUtils.getUserClass(handler);
PortletHandlerMethodResolver resolver = this.methodResolverCache.get(handlerClass);
if (resolver == null) {
synchronized (this.methodResolverCache) {
@@ -554,7 +554,7 @@ public class AnnotationMethodHandlerAdapter extends PortletContentGenerator
}
@Override
protected void raiseMissingParameterException(String paramName, Class paramType) throws Exception {
protected void raiseMissingParameterException(String paramName, Class<?> paramType) throws Exception {
throw new MissingPortletRequestParameterException(paramName, paramType.getSimpleName());
}
@@ -591,7 +591,7 @@ public class AnnotationMethodHandlerAdapter extends PortletContentGenerator
}
@Override
protected Object resolveCookieValue(String cookieName, Class paramType, NativeWebRequest webRequest)
protected Object resolveCookieValue(String cookieName, Class<?> paramType, NativeWebRequest webRequest)
throws Exception {
PortletRequest portletRequest = webRequest.getNativeRequest(PortletRequest.class);
@@ -686,7 +686,7 @@ public class AnnotationMethodHandlerAdapter extends PortletContentGenerator
}
@SuppressWarnings("unchecked")
public ModelAndView getModelAndView(Method handlerMethod, Class handlerType, Object returnValue, ExtendedModelMap implicitModel,
public ModelAndView getModelAndView(Method handlerMethod, Class<?> handlerType, Object returnValue, ExtendedModelMap implicitModel,
PortletWebRequest webRequest) {
// Invoke custom resolvers if present...
if (customModelAndViewResolvers != null) {
@@ -725,7 +725,7 @@ public class AnnotationMethodHandlerAdapter extends PortletContentGenerator
return new ModelAndView().addAllObjects(implicitModel);
}
else if (returnValue instanceof Map) {
return new ModelAndView().addAllObjects(implicitModel).addAllObjects((Map) returnValue);
return new ModelAndView().addAllObjects(implicitModel).addAllObjects((Map<String, Object>) returnValue);
}
else if (returnValue instanceof String) {
return new ModelAndView((String) returnValue).addAllObjects(implicitModel);

View File

@@ -386,7 +386,7 @@ public class AnnotationMethodHandlerExceptionResolver extends AbstractHandlerExc
return new ModelAndView().addAllObjects(((Model) returnValue).asMap());
}
else if (returnValue instanceof Map) {
return new ModelAndView().addAllObjects((Map) returnValue);
return new ModelAndView().addAllObjects((Map<String, Object>) returnValue);
}
else if (returnValue instanceof View) {
return new ModelAndView(returnValue);

View File

@@ -21,6 +21,7 @@ import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Set;
import javax.portlet.ActionRequest;
import javax.portlet.ClientDataRequest;
import javax.portlet.Event;
@@ -283,7 +284,7 @@ public class DefaultAnnotationHandlerMapping extends AbstractMapBasedHandlerMapp
}
@Override
public int compareTo(Object other) {
public int compareTo(PortletRequestMappingPredicate other) {
return (other instanceof SpecialRequestTypePredicate ? -1 : compareParams(other));
}
}
@@ -300,7 +301,7 @@ public class DefaultAnnotationHandlerMapping extends AbstractMapBasedHandlerMapp
}
@Override
public int compareTo(Object other) {
public int compareTo(PortletRequestMappingPredicate other) {
return (other instanceof SpecialRequestTypePredicate ? 1 : compareParams(other));
}
}
@@ -327,7 +328,7 @@ public class DefaultAnnotationHandlerMapping extends AbstractMapBasedHandlerMapp
}
@Override
public int compareTo(Object other) {
public int compareTo(PortletRequestMappingPredicate other) {
if (other instanceof TypeLevelMappingPredicate) {
return 1;
}
@@ -371,7 +372,7 @@ public class DefaultAnnotationHandlerMapping extends AbstractMapBasedHandlerMapp
}
@Override
public int compareTo(Object other) {
public int compareTo(PortletRequestMappingPredicate other) {
if (other instanceof TypeLevelMappingPredicate) {
return 1;
}
@@ -413,7 +414,7 @@ public class DefaultAnnotationHandlerMapping extends AbstractMapBasedHandlerMapp
}
@Override
public int compareTo(Object other) {
public int compareTo(PortletRequestMappingPredicate other) {
if (other instanceof ResourceMappingPredicate) {
boolean hasResourceId = !"".equals(this.resourceId);
boolean otherHasResourceId = !"".equals(((ResourceMappingPredicate) other).resourceId);
@@ -454,7 +455,7 @@ public class DefaultAnnotationHandlerMapping extends AbstractMapBasedHandlerMapp
}
@Override
public int compareTo(Object other) {
public int compareTo(PortletRequestMappingPredicate other) {
if (other instanceof EventMappingPredicate) {
boolean hasEventName = !"".equals(this.eventName);
boolean otherHasEventName = !"".equals(((EventMappingPredicate) other).eventName);

View File

@@ -23,6 +23,7 @@ import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.PortletContext;
@@ -203,7 +204,7 @@ public abstract class PortletUtils {
* @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(PortletSession session, String name, Class clazz)
public static Object getOrCreateSessionAttribute(PortletSession session, String name, Class<?> clazz)
throws IllegalArgumentException {
return getOrCreateSessionAttribute(session, name, clazz, PortletSession.PORTLET_SCOPE);
@@ -221,7 +222,7 @@ public abstract class PortletUtils {
* @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(PortletSession session, String name, Class clazz, int scope)
public static Object getOrCreateSessionAttribute(PortletSession session, String name, Class<?> clazz, int scope)
throws IllegalArgumentException {
Assert.notNull(session, "Session must not be null");
@@ -411,13 +412,13 @@ public abstract class PortletUtils {
*/
public static Map<String, Object> getParametersStartingWith(PortletRequest 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);
@@ -445,9 +446,9 @@ public abstract class PortletUtils {
* @return the page specified in the request, or current page if not found
*/
public static int getTargetPage(PortletRequest 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];
@@ -472,9 +473,9 @@ public abstract class PortletUtils {
*/
public static void passAllParametersToRenderPhase(ActionRequest request, ActionResponse response) {
try {
Enumeration en = request.getParameterNames();
Enumeration<String> en = request.getParameterNames();
while (en.hasMoreElements()) {
String param = (String) en.nextElement();
String param = en.nextElement();
String values[] = request.getParameterValues(param);
response.setRenderParameter(param, values);
}