From 13239a0c3d5bf226998f2da9eb66014118972a26 Mon Sep 17 00:00:00 2001 From: Philippe Marschall Date: Sat, 11 Feb 2012 20:32:37 +0100 Subject: [PATCH] Fix compiler warnings This patch fixes several compiler warnings that do not point to code problems. Two kinds of warnings are fixed. First in a lot of cases @SuppressWarnings("unchecked") is used although there are no unchecked casts happening. This seems to be a leftover from when the code base was on Java 1.4, now that the code base was moved to Java 1.5 these are no longer necessary. Secondly there some places where the raw types of List and Class are used where there wildcard types (List and Class) would work just as well without causing any raw type warnings. These changes are beneficial particularly when working in Eclipse or other IDEs because it reduces 'noise', helping to isolate actual potential problems in the code. The following changes have been made: - remove @SuppressWarnings where no longer needed - use wildcard types instead of raw types where possible --- .../org/springframework/aop/framework/ProxyFactory.java | 4 +--- .../factory/config/DestructionAwareAttributeHolder.java | 5 +---- .../scheduling/quartz/JobDetailFactoryBean.java | 3 +-- .../context/event/SourceFilteringListener.java | 3 +-- .../websphere/WebSphereClassLoaderAdapter.java | 5 ++--- .../context/support/TestProxyFactoryBean.java | 4 ++-- .../core/LocalVariableTableParameterNameDiscoverer.java | 3 +-- .../java/org/springframework/core/MethodParameter.java | 1 - .../org/springframework/jdbc/core/ColumnMapRowMapper.java | 3 +-- .../web/context/request/ServletRequestAttributes.java | 3 +-- .../web/context/request/ServletWebRequest.java | 8 +------- 11 files changed, 12 insertions(+), 30 deletions(-) diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/ProxyFactory.java b/spring-aop/src/main/java/org/springframework/aop/framework/ProxyFactory.java index 9b0d8ceb732..989160bf65b 100644 --- a/spring-aop/src/main/java/org/springframework/aop/framework/ProxyFactory.java +++ b/spring-aop/src/main/java/org/springframework/aop/framework/ProxyFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2009 the original author or authors. + * Copyright 2002-2012 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -93,7 +93,6 @@ public class ProxyFactory extends ProxyCreatorSupport { * (if necessary for proxy creation). * @return the proxy object */ - @SuppressWarnings("unchecked") public Object getProxy() { return createAopProxy().getProxy(); } @@ -107,7 +106,6 @@ public class ProxyFactory extends ProxyCreatorSupport { * (or null for the low-level proxy facility's default) * @return the proxy object */ - @SuppressWarnings("unchecked") public Object getProxy(ClassLoader classLoader) { return createAopProxy().getProxy(classLoader); } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/DestructionAwareAttributeHolder.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/DestructionAwareAttributeHolder.java index ae7276fb33e..52ecf9d88cd 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/config/DestructionAwareAttributeHolder.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/DestructionAwareAttributeHolder.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2011 the original author or authors. + * Copyright 2002-2012 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -59,7 +59,6 @@ public class DestructionAwareAttributeHolder implements Serializable { * the name of the attribute to be returned * @return the attribute value or null if not available */ - @SuppressWarnings("unchecked") public Object getAttribute(String name) { return attributes.get(name); } @@ -75,7 +74,6 @@ public class DestructionAwareAttributeHolder implements Serializable { * @return any previously object stored under the same name, if any, * null otherwise */ - @SuppressWarnings("unchecked") public Object setAttribute(String name, Object value) { return attributes.put(name, value); } @@ -101,7 +99,6 @@ public class DestructionAwareAttributeHolder implements Serializable { * @return the removed object, or null if no object was present * @see #registerDestructionCallback */ - @SuppressWarnings("unchecked") public Object removeAttribute(String name) { Object value = attributes.remove(name); diff --git a/spring-context-support/src/main/java/org/springframework/scheduling/quartz/JobDetailFactoryBean.java b/spring-context-support/src/main/java/org/springframework/scheduling/quartz/JobDetailFactoryBean.java index 6df333fcca5..921a5e03d46 100644 --- a/spring-context-support/src/main/java/org/springframework/scheduling/quartz/JobDetailFactoryBean.java +++ b/spring-context-support/src/main/java/org/springframework/scheduling/quartz/JobDetailFactoryBean.java @@ -168,7 +168,6 @@ public class JobDetailFactoryBean } - @SuppressWarnings("unchecked") public void afterPropertiesSet() { if (this.name == null) { this.name = this.beanName; @@ -196,7 +195,7 @@ public class JobDetailFactoryBean this.jobDetail = jdi; */ - Class jobDetailClass; + Class jobDetailClass; try { jobDetailClass = getClass().getClassLoader().loadClass("org.quartz.impl.JobDetailImpl"); } diff --git a/spring-context/src/main/java/org/springframework/context/event/SourceFilteringListener.java b/spring-context/src/main/java/org/springframework/context/event/SourceFilteringListener.java index 3fe6babc3c8..a9326c5b168 100644 --- a/spring-context/src/main/java/org/springframework/context/event/SourceFilteringListener.java +++ b/spring-context/src/main/java/org/springframework/context/event/SourceFilteringListener.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2009 the original author or authors. + * Copyright 2002-2012 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -88,7 +88,6 @@ public class SourceFilteringListener implements SmartApplicationListener { *

The default implementation invokes the specified delegate, if any. * @param event the event to process (matching the specified source) */ - @SuppressWarnings("unchecked") protected void onApplicationEventInternal(ApplicationEvent event) { if (this.delegate == null) { throw new IllegalStateException( diff --git a/spring-context/src/main/java/org/springframework/instrument/classloading/websphere/WebSphereClassLoaderAdapter.java b/spring-context/src/main/java/org/springframework/instrument/classloading/websphere/WebSphereClassLoaderAdapter.java index 2e0fa5cf042..798393676b0 100644 --- a/spring-context/src/main/java/org/springframework/instrument/classloading/websphere/WebSphereClassLoaderAdapter.java +++ b/spring-context/src/main/java/org/springframework/instrument/classloading/websphere/WebSphereClassLoaderAdapter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2011 the original author or authors. + * Copyright 2002-2012 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -91,12 +91,11 @@ class WebSphereClassLoaderAdapter { } } - @SuppressWarnings("unchecked") public ClassLoader getThrowawayClassLoader() { try { ClassLoader loader = (ClassLoader) cloneConstructor.newInstance(getClassLoader()); // clear out the transformers (copied as well) - List list = (List) transformerList.get(loader); + List list = (List) transformerList.get(loader); list.clear(); return loader; } diff --git a/spring-context/src/test/java/org/springframework/context/support/TestProxyFactoryBean.java b/spring-context/src/test/java/org/springframework/context/support/TestProxyFactoryBean.java index 76027827c92..0fa4b0e392e 100644 --- a/spring-context/src/test/java/org/springframework/context/support/TestProxyFactoryBean.java +++ b/spring-context/src/test/java/org/springframework/context/support/TestProxyFactoryBean.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2011 the original author or authors. + * Copyright 2002-2012 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,7 +20,7 @@ import org.springframework.aop.framework.AbstractSingletonProxyFactoryBean; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactoryAware; -@SuppressWarnings({ "serial", "deprecation" }) +@SuppressWarnings("serial") public class TestProxyFactoryBean extends AbstractSingletonProxyFactoryBean implements BeanFactoryAware { @Override diff --git a/spring-core/src/main/java/org/springframework/core/LocalVariableTableParameterNameDiscoverer.java b/spring-core/src/main/java/org/springframework/core/LocalVariableTableParameterNameDiscoverer.java index 6f0a29e8a7d..9cf3f92a89f 100644 --- a/spring-core/src/main/java/org/springframework/core/LocalVariableTableParameterNameDiscoverer.java +++ b/spring-core/src/main/java/org/springframework/core/LocalVariableTableParameterNameDiscoverer.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * Copyright 2002-2012 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -77,7 +77,6 @@ public class LocalVariableTableParameterNameDiscoverer implements ParameterNameD return null; } - @SuppressWarnings("unchecked") public String[] getParameterNames(Constructor ctor) { Class declaringClass = ctor.getDeclaringClass(); Map map = this.parameterNamesCache.get(declaringClass); diff --git a/spring-core/src/main/java/org/springframework/core/MethodParameter.java b/spring-core/src/main/java/org/springframework/core/MethodParameter.java index 2ca92c33b6b..df4f1c3099e 100644 --- a/spring-core/src/main/java/org/springframework/core/MethodParameter.java +++ b/spring-core/src/main/java/org/springframework/core/MethodParameter.java @@ -281,7 +281,6 @@ public class MethodParameter { * @param annotationType the annotation type to look for * @return the annotation object, or null if not found */ - @SuppressWarnings("unchecked") public T getMethodAnnotation(Class annotationType) { return getAnnotatedElement().getAnnotation(annotationType); } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/ColumnMapRowMapper.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/ColumnMapRowMapper.java index 3fa01e271aa..fffcf43ec94 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/ColumnMapRowMapper.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/ColumnMapRowMapper.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2009 the original author or authors. + * Copyright 2002-2012 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -67,7 +67,6 @@ public class ColumnMapRowMapper implements RowMapper> { * @return the new Map instance * @see org.springframework.util.LinkedCaseInsensitiveMap */ - @SuppressWarnings("unchecked") protected Map createColumnMap(int columnCount) { return new LinkedCaseInsensitiveMap(columnCount); } diff --git a/spring-web/src/main/java/org/springframework/web/context/request/ServletRequestAttributes.java b/spring-web/src/main/java/org/springframework/web/context/request/ServletRequestAttributes.java index 236d84a0846..5791c7f1dcd 100644 --- a/spring-web/src/main/java/org/springframework/web/context/request/ServletRequestAttributes.java +++ b/spring-web/src/main/java/org/springframework/web/context/request/ServletRequestAttributes.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2009 the original author or authors. + * Copyright 2002-2012 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -159,7 +159,6 @@ public class ServletRequestAttributes extends AbstractRequestAttributes { } } - @SuppressWarnings("unchecked") public String[] getAttributeNames(int scope) { if (scope == SCOPE_REQUEST) { if (!isRequestActive()) { diff --git a/spring-web/src/main/java/org/springframework/web/context/request/ServletWebRequest.java b/spring-web/src/main/java/org/springframework/web/context/request/ServletWebRequest.java index 9cb56566ed1..d9a75991d33 100644 --- a/spring-web/src/main/java/org/springframework/web/context/request/ServletWebRequest.java +++ b/spring-web/src/main/java/org/springframework/web/context/request/ServletWebRequest.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2011 the original author or authors. + * Copyright 2002-2012 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -87,12 +87,10 @@ public class ServletWebRequest extends ServletRequestAttributes implements Nativ return getResponse(); } - @SuppressWarnings("unchecked") public T getNativeRequest(Class requiredType) { return WebUtils.getNativeRequest(getRequest(), requiredType); } - @SuppressWarnings("unchecked") public T getNativeResponse(Class requiredType) { return WebUtils.getNativeResponse(getResponse(), requiredType); } @@ -102,13 +100,11 @@ public class ServletWebRequest extends ServletRequestAttributes implements Nativ return getRequest().getHeader(headerName); } - @SuppressWarnings("unchecked") public String[] getHeaderValues(String headerName) { String[] headerValues = StringUtils.toStringArray(getRequest().getHeaders(headerName)); return (!ObjectUtils.isEmpty(headerValues) ? headerValues : null); } - @SuppressWarnings("unchecked") public Iterator getHeaderNames() { return CollectionUtils.toIterator(getRequest().getHeaderNames()); } @@ -121,12 +117,10 @@ public class ServletWebRequest extends ServletRequestAttributes implements Nativ return getRequest().getParameterValues(paramName); } - @SuppressWarnings("unchecked") public Iterator getParameterNames() { return CollectionUtils.toIterator(getRequest().getParameterNames()); } - @SuppressWarnings("unchecked") public Map getParameterMap() { return getRequest().getParameterMap(); }