From f30b7e3125105e75a0c10a75a27949a2a6937f86 Mon Sep 17 00:00:00 2001 From: Chris Beams Date: Fri, 6 May 2011 19:00:14 +0000 Subject: [PATCH] Fix generics and serialization warnings --- .../AutowiredAnnotationBeanPostProcessor.java | 26 ++++++------- ...nitDestroyAnnotationBeanPostProcessor.java | 11 +++--- .../RequiredAnnotationBeanPostProcessor.java | 4 +- .../InstantiationAwareBeanPostProcessor.java | 2 +- ...ntiationAwareBeanPostProcessorAdapter.java | 4 +- .../CommonAnnotationBeanPostProcessor.java | 38 +++++++++++-------- .../AsyncAnnotationBeanPostProcessor.java | 3 +- .../core/annotation/AnnotationUtils.java | 8 ++-- ...ersistenceAnnotationBeanPostProcessor.java | 12 +++--- 9 files changed, 59 insertions(+), 49 deletions(-) diff --git a/org.springframework.beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java b/org.springframework.beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java index 45247a384cf..81690732fa8 100644 --- a/org.springframework.beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java +++ b/org.springframework.beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * Copyright 2002-2011 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. @@ -115,8 +115,8 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean private ConfigurableListableBeanFactory beanFactory; - private final Map, Constructor[]> candidateConstructorsCache = - new ConcurrentHashMap, Constructor[]>(); + private final Map, Constructor[]> candidateConstructorsCache = + new ConcurrentHashMap, Constructor[]>(); private final Map, InjectionMetadata> injectionMetadataCache = new ConcurrentHashMap, InjectionMetadata>(); @@ -209,7 +209,7 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean } - public void postProcessMergedBeanDefinition(RootBeanDefinition beanDefinition, Class beanType, String beanName) { + public void postProcessMergedBeanDefinition(RootBeanDefinition beanDefinition, Class beanType, String beanName) { if (beanType != null) { InjectionMetadata metadata = findAutowiringMetadata(beanType); metadata.checkConfigMembers(beanDefinition); @@ -217,17 +217,17 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean } @Override - public Constructor[] determineCandidateConstructors(Class beanClass, String beanName) throws BeansException { + public Constructor[] determineCandidateConstructors(Class beanClass, String beanName) throws BeansException { // Quick check on the concurrent map first, with minimal locking. - Constructor[] candidateConstructors = this.candidateConstructorsCache.get(beanClass); + Constructor[] candidateConstructors = this.candidateConstructorsCache.get(beanClass); if (candidateConstructors == null) { synchronized (this.candidateConstructorsCache) { candidateConstructors = this.candidateConstructorsCache.get(beanClass); if (candidateConstructors == null) { - Constructor[] rawCandidates = beanClass.getDeclaredConstructors(); - List candidates = new ArrayList(rawCandidates.length); - Constructor requiredConstructor = null; - Constructor defaultConstructor = null; + Constructor[] rawCandidates = beanClass.getDeclaredConstructors(); + List> candidates = new ArrayList>(rawCandidates.length); + Constructor requiredConstructor = null; + Constructor defaultConstructor = null; for (Constructor candidate : rawCandidates) { Annotation annotation = findAutowiredAnnotation(candidate); if (annotation != null) { @@ -305,7 +305,7 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean } - private InjectionMetadata findAutowiringMetadata(Class clazz) { + private InjectionMetadata findAutowiringMetadata(Class clazz) { // Quick check on the concurrent map first, with minimal locking. InjectionMetadata metadata = this.injectionMetadataCache.get(clazz); if (metadata == null) { @@ -320,7 +320,7 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean return metadata; } - private InjectionMetadata buildAutowiringMetadata(Class clazz) { + private InjectionMetadata buildAutowiringMetadata(Class clazz) { LinkedList elements = new LinkedList(); Class targetClass = clazz; @@ -534,7 +534,7 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean arguments = resolveCachedArguments(beanName); } else { - Class[] paramTypes = method.getParameterTypes(); + Class[] paramTypes = method.getParameterTypes(); arguments = new Object[paramTypes.length]; DependencyDescriptor[] descriptors = new DependencyDescriptor[paramTypes.length]; Set autowiredBeanNames = new LinkedHashSet(paramTypes.length); diff --git a/org.springframework.beans/src/main/java/org/springframework/beans/factory/annotation/InitDestroyAnnotationBeanPostProcessor.java b/org.springframework.beans/src/main/java/org/springframework/beans/factory/annotation/InitDestroyAnnotationBeanPostProcessor.java index eaf270f8131..4c2db7df864 100644 --- a/org.springframework.beans/src/main/java/org/springframework/beans/factory/annotation/InitDestroyAnnotationBeanPostProcessor.java +++ b/org.springframework.beans/src/main/java/org/springframework/beans/factory/annotation/InitDestroyAnnotationBeanPostProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2009 the original author or authors. + * Copyright 2002-2011 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. @@ -71,6 +71,7 @@ import org.springframework.util.ReflectionUtils; * @see #setInitAnnotationType * @see #setDestroyAnnotationType */ +@SuppressWarnings("serial") public class InitDestroyAnnotationBeanPostProcessor implements DestructionAwareBeanPostProcessor, MergedBeanDefinitionPostProcessor, PriorityOrdered, Serializable { @@ -117,7 +118,7 @@ public class InitDestroyAnnotationBeanPostProcessor } - public void postProcessMergedBeanDefinition(RootBeanDefinition beanDefinition, Class beanType, String beanName) { + public void postProcessMergedBeanDefinition(RootBeanDefinition beanDefinition, Class beanType, String beanName) { if (beanType != null) { LifecycleMetadata metadata = findLifecycleMetadata(beanType); metadata.checkConfigMembers(beanDefinition); @@ -162,7 +163,7 @@ public class InitDestroyAnnotationBeanPostProcessor } - private LifecycleMetadata findLifecycleMetadata(Class clazz) { + private LifecycleMetadata findLifecycleMetadata(Class clazz) { if (this.lifecycleMetadataCache == null) { // Happens after deserialization, during destruction... return buildLifecycleMetadata(clazz); @@ -182,7 +183,7 @@ public class InitDestroyAnnotationBeanPostProcessor return metadata; } - private LifecycleMetadata buildLifecycleMetadata(Class clazz) { + private LifecycleMetadata buildLifecycleMetadata(Class clazz) { final boolean debug = logger.isDebugEnabled(); LinkedList initMethods = new LinkedList(); LinkedList destroyMethods = new LinkedList(); @@ -242,7 +243,7 @@ public class InitDestroyAnnotationBeanPostProcessor private final Set destroyMethods; - public LifecycleMetadata(Class targetClass, Collection initMethods, + public LifecycleMetadata(Class targetClass, Collection initMethods, Collection destroyMethods) { this.initMethods = new LinkedHashSet(); diff --git a/org.springframework.beans/src/main/java/org/springframework/beans/factory/annotation/RequiredAnnotationBeanPostProcessor.java b/org.springframework.beans/src/main/java/org/springframework/beans/factory/annotation/RequiredAnnotationBeanPostProcessor.java index a38041dd711..21925d6a67f 100644 --- a/org.springframework.beans/src/main/java/org/springframework/beans/factory/annotation/RequiredAnnotationBeanPostProcessor.java +++ b/org.springframework.beans/src/main/java/org/springframework/beans/factory/annotation/RequiredAnnotationBeanPostProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2009 the original author or authors. + * Copyright 2002-2011 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. @@ -129,7 +129,7 @@ public class RequiredAnnotationBeanPostProcessor extends InstantiationAwareBeanP } - public void postProcessMergedBeanDefinition(RootBeanDefinition beanDefinition, Class beanType, String beanName) { + public void postProcessMergedBeanDefinition(RootBeanDefinition beanDefinition, Class beanType, String beanName) { } @Override diff --git a/org.springframework.beans/src/main/java/org/springframework/beans/factory/config/InstantiationAwareBeanPostProcessor.java b/org.springframework.beans/src/main/java/org/springframework/beans/factory/config/InstantiationAwareBeanPostProcessor.java index 00e4700b71f..f0d5b59a92e 100644 --- a/org.springframework.beans/src/main/java/org/springframework/beans/factory/config/InstantiationAwareBeanPostProcessor.java +++ b/org.springframework.beans/src/main/java/org/springframework/beans/factory/config/InstantiationAwareBeanPostProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2011 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. diff --git a/org.springframework.beans/src/main/java/org/springframework/beans/factory/config/InstantiationAwareBeanPostProcessorAdapter.java b/org.springframework.beans/src/main/java/org/springframework/beans/factory/config/InstantiationAwareBeanPostProcessorAdapter.java index 9dbb5adc67a..49eeaaf532f 100644 --- a/org.springframework.beans/src/main/java/org/springframework/beans/factory/config/InstantiationAwareBeanPostProcessorAdapter.java +++ b/org.springframework.beans/src/main/java/org/springframework/beans/factory/config/InstantiationAwareBeanPostProcessorAdapter.java @@ -43,7 +43,7 @@ public abstract class InstantiationAwareBeanPostProcessorAdapter implements Smar return null; } - public Constructor[] determineCandidateConstructors(Class beanClass, String beanName) throws BeansException { + public Constructor[] determineCandidateConstructors(Class beanClass, String beanName) throws BeansException { return null; } @@ -51,7 +51,7 @@ public abstract class InstantiationAwareBeanPostProcessorAdapter implements Smar return bean; } - public Object postProcessBeforeInstantiation(Class beanClass, String beanName) throws BeansException { + public Object postProcessBeforeInstantiation(Class beanClass, String beanName) throws BeansException { return null; } diff --git a/org.springframework.context/src/main/java/org/springframework/context/annotation/CommonAnnotationBeanPostProcessor.java b/org.springframework.context/src/main/java/org/springframework/context/annotation/CommonAnnotationBeanPostProcessor.java index d981c811a5c..40f0a9066b1 100644 --- a/org.springframework.context/src/main/java/org/springframework/context/annotation/CommonAnnotationBeanPostProcessor.java +++ b/org.springframework.context/src/main/java/org/springframework/context/annotation/CommonAnnotationBeanPostProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2009 the original author or authors. + * Copyright 2002-2011 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. @@ -135,6 +135,7 @@ import org.springframework.util.StringUtils; * @see org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor * @see org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor */ +@SuppressWarnings("serial") public class CommonAnnotationBeanPostProcessor extends InitDestroyAnnotationBeanPostProcessor implements InstantiationAwareBeanPostProcessor, BeanFactoryAware, Serializable { @@ -145,13 +146,17 @@ public class CommonAnnotationBeanPostProcessor extends InitDestroyAnnotationBean static { ClassLoader cl = CommonAnnotationBeanPostProcessor.class.getClassLoader(); try { - webServiceRefClass = (Class) cl.loadClass("javax.xml.ws.WebServiceRef"); + @SuppressWarnings("unchecked") + Class clazz = (Class) cl.loadClass("javax.xml.ws.WebServiceRef"); + webServiceRefClass = clazz; } catch (ClassNotFoundException ex) { webServiceRefClass = null; } try { - ejbRefClass = (Class) cl.loadClass("javax.ejb.EJB"); + @SuppressWarnings("unchecked") + Class clazz = (Class) cl.loadClass("javax.ejb.EJB"); + ejbRefClass = clazz; } catch (ClassNotFoundException ex) { ejbRefClass = null; @@ -273,7 +278,7 @@ public class CommonAnnotationBeanPostProcessor extends InitDestroyAnnotationBean @Override - public void postProcessMergedBeanDefinition(RootBeanDefinition beanDefinition, Class beanType, String beanName) { + public void postProcessMergedBeanDefinition(RootBeanDefinition beanDefinition, Class beanType, String beanName) { super.postProcessMergedBeanDefinition(beanDefinition, beanType, beanName); if (beanType != null) { InjectionMetadata metadata = findResourceMetadata(beanType); @@ -281,7 +286,7 @@ public class CommonAnnotationBeanPostProcessor extends InitDestroyAnnotationBean } } - public Object postProcessBeforeInstantiation(Class beanClass, String beanName) throws BeansException { + public Object postProcessBeforeInstantiation(Class beanClass, String beanName) throws BeansException { return null; } @@ -303,7 +308,7 @@ public class CommonAnnotationBeanPostProcessor extends InitDestroyAnnotationBean } - private InjectionMetadata findResourceMetadata(final Class clazz) { + private InjectionMetadata findResourceMetadata(final Class clazz) { // Quick check on the concurrent map first, with minimal locking. InjectionMetadata metadata = this.injectionMetadataCache.get(clazz); if (metadata == null) { @@ -365,7 +370,7 @@ public class CommonAnnotationBeanPostProcessor extends InitDestroyAnnotationBean if (Modifier.isStatic(method.getModifiers())) { throw new IllegalStateException("@Resource annotation is not supported on static methods"); } - Class[] paramTypes = method.getParameterTypes(); + Class[] paramTypes = method.getParameterTypes(); if (paramTypes.length != 1) { throw new IllegalStateException("@Resource annotation requires a single-arg method: " + method); } @@ -502,6 +507,7 @@ public class CommonAnnotationBeanPostProcessor extends InitDestroyAnnotationBean */ private class ResourceElement extends LookupElement { + @SuppressWarnings("unused") protected boolean shareable = true; public ResourceElement(Member member, PropertyDescriptor pd) { @@ -512,7 +518,7 @@ public class CommonAnnotationBeanPostProcessor extends InitDestroyAnnotationBean protected void initAnnotation(AnnotatedElement ae) { Resource resource = ae.getAnnotation(Resource.class); String resourceName = resource.name(); - Class resourceType = resource.type(); + Class resourceType = resource.type(); this.isDefaultName = !StringUtils.hasLength(resourceName); if (this.isDefaultName) { resourceName = this.member.getName(); @@ -549,7 +555,7 @@ public class CommonAnnotationBeanPostProcessor extends InitDestroyAnnotationBean */ private class WebServiceRefElement extends LookupElement { - private Class elementType; + private Class elementType; private String wsdlLocation; @@ -561,7 +567,7 @@ public class CommonAnnotationBeanPostProcessor extends InitDestroyAnnotationBean protected void initAnnotation(AnnotatedElement ae) { WebServiceRef resource = ae.getAnnotation(WebServiceRef.class); String resourceName = resource.name(); - Class resourceType = resource.type(); + Class resourceType = resource.type(); this.isDefaultName = !StringUtils.hasLength(resourceName); if (this.isDefaultName) { resourceName = this.member.getName(); @@ -604,7 +610,7 @@ public class CommonAnnotationBeanPostProcessor extends InitDestroyAnnotationBean } if (StringUtils.hasLength(this.wsdlLocation)) { try { - Constructor ctor = this.lookupType.getConstructor(new Class[] {URL.class, QName.class}); + Constructor ctor = this.lookupType.getConstructor(new Class[] {URL.class, QName.class}); WebServiceClient clientAnn = this.lookupType.getAnnotation(WebServiceClient.class); if (clientAnn == null) { throw new IllegalStateException("JAX-WS Service class [" + this.lookupType.getName() + @@ -656,7 +662,7 @@ public class CommonAnnotationBeanPostProcessor extends InitDestroyAnnotationBean resourceName = Introspector.decapitalize(resourceName.substring(3)); } } - Class resourceType = resource.beanInterface(); + Class resourceType = resource.beanInterface(); if (resourceType != null && !Object.class.equals(resourceType)) { checkResourceType(resourceType); } @@ -698,20 +704,20 @@ public class CommonAnnotationBeanPostProcessor extends InitDestroyAnnotationBean */ private static class LookupDependencyDescriptor extends DependencyDescriptor { - private final Class lookupType; + private final Class lookupType; - public LookupDependencyDescriptor(Field field, Class lookupType) { + public LookupDependencyDescriptor(Field field, Class lookupType) { super(field, true); this.lookupType = lookupType; } - public LookupDependencyDescriptor(Method method, Class lookupType) { + public LookupDependencyDescriptor(Method method, Class lookupType) { super(new MethodParameter(method, 0), true); this.lookupType = lookupType; } @Override - public Class getDependencyType() { + public Class getDependencyType() { return this.lookupType; } } diff --git a/org.springframework.context/src/main/java/org/springframework/scheduling/annotation/AsyncAnnotationBeanPostProcessor.java b/org.springframework.context/src/main/java/org/springframework/scheduling/annotation/AsyncAnnotationBeanPostProcessor.java index d363a538ab1..31d4585c265 100644 --- a/org.springframework.context/src/main/java/org/springframework/scheduling/annotation/AsyncAnnotationBeanPostProcessor.java +++ b/org.springframework.context/src/main/java/org/springframework/scheduling/annotation/AsyncAnnotationBeanPostProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * Copyright 2002-2011 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. @@ -51,6 +51,7 @@ import org.springframework.util.ClassUtils; * @see Async * @see AsyncAnnotationAdvisor */ +@SuppressWarnings("serial") public class AsyncAnnotationBeanPostProcessor extends ProxyConfig implements BeanPostProcessor, BeanClassLoaderAware, InitializingBean, Ordered { diff --git a/org.springframework.core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java b/org.springframework.core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java index 860c6423329..31adc8956d4 100644 --- a/org.springframework.core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java +++ b/org.springframework.core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java @@ -51,7 +51,7 @@ public abstract class AnnotationUtils { /** The attribute name for annotations with a single element */ static final String VALUE = "value"; - private static final Map annotatedInterfaceCache = new WeakHashMap(); + private static final Map, Boolean> annotatedInterfaceCache = new WeakHashMap, Boolean>(); /** @@ -120,7 +120,7 @@ public abstract class AnnotationUtils { return annotation; } - private static A searchOnInterfaces(Method method, Class annotationType, Class[] ifcs) { + private static A searchOnInterfaces(Method method, Class annotationType, Class[] ifcs) { A annotation = null; for (Class iface : ifcs) { if (isInterfaceWithAnnotatedMethods(iface)) { @@ -302,10 +302,10 @@ public abstract class AnnotationUtils { Object value = method.invoke(annotation); if (classValuesAsString) { if (value instanceof Class) { - value = ((Class) value).getName(); + value = ((Class) value).getName(); } else if (value instanceof Class[]) { - Class[] clazzArray = (Class[]) value; + Class[] clazzArray = (Class[]) value; String[] newValue = new String[clazzArray.length]; for (int i = 0; i < clazzArray.length; i++) { newValue[i] = clazzArray[i].getName(); diff --git a/org.springframework.orm/src/main/java/org/springframework/orm/jpa/support/PersistenceAnnotationBeanPostProcessor.java b/org.springframework.orm/src/main/java/org/springframework/orm/jpa/support/PersistenceAnnotationBeanPostProcessor.java index d03801fe41c..5d3f3c5b310 100644 --- a/org.springframework.orm/src/main/java/org/springframework/orm/jpa/support/PersistenceAnnotationBeanPostProcessor.java +++ b/org.springframework.orm/src/main/java/org/springframework/orm/jpa/support/PersistenceAnnotationBeanPostProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * Copyright 2002-2011 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. @@ -27,6 +27,7 @@ import java.util.LinkedList; import java.util.Map; import java.util.Properties; import java.util.concurrent.ConcurrentHashMap; + import javax.persistence.EntityManager; import javax.persistence.EntityManagerFactory; import javax.persistence.PersistenceContext; @@ -159,6 +160,7 @@ import org.springframework.util.ObjectUtils; * @see javax.persistence.PersistenceUnit * @see javax.persistence.PersistenceContext */ +@SuppressWarnings("serial") public class PersistenceAnnotationBeanPostProcessor implements InstantiationAwareBeanPostProcessor, DestructionAwareBeanPostProcessor, MergedBeanDefinitionPostProcessor, PriorityOrdered, BeanFactoryAware, Serializable { @@ -315,14 +317,14 @@ public class PersistenceAnnotationBeanPostProcessor } - public void postProcessMergedBeanDefinition(RootBeanDefinition beanDefinition, Class beanType, String beanName) { + public void postProcessMergedBeanDefinition(RootBeanDefinition beanDefinition, Class beanType, String beanName) { if (beanType != null) { InjectionMetadata metadata = findPersistenceMetadata(beanType); metadata.checkConfigMembers(beanDefinition); } } - public Object postProcessBeforeInstantiation(Class beanClass, String beanName) throws BeansException { + public Object postProcessBeforeInstantiation(Class beanClass, String beanName) throws BeansException { return null; } @@ -357,7 +359,7 @@ public class PersistenceAnnotationBeanPostProcessor } - private InjectionMetadata findPersistenceMetadata(final Class clazz) { + private InjectionMetadata findPersistenceMetadata(final Class clazz) { // Quick check on the concurrent map first, with minimal locking. InjectionMetadata metadata = this.injectionMetadataCache.get(clazz); if (metadata == null) { @@ -592,7 +594,7 @@ public class PersistenceAnnotationBeanPostProcessor AnnotatedElement ae = (AnnotatedElement) member; PersistenceContext pc = ae.getAnnotation(PersistenceContext.class); PersistenceUnit pu = ae.getAnnotation(PersistenceUnit.class); - Class resourceType = EntityManager.class; + Class resourceType = EntityManager.class; if (pc != null) { if (pu != null) { throw new IllegalStateException("Member may only be annotated with either " +