diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/AdvisedSupport.java b/spring-aop/src/main/java/org/springframework/aop/framework/AdvisedSupport.java index 40940374d8..515f1621ad 100644 --- a/spring-aop/src/main/java/org/springframework/aop/framework/AdvisedSupport.java +++ b/spring-aop/src/main/java/org/springframework/aop/framework/AdvisedSupport.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 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. @@ -234,7 +234,7 @@ public class AdvisedSupport extends ProxyConfig implements Advised { @Override public Class[] getProxiedInterfaces() { - return this.interfaces.toArray(new Class[this.interfaces.size()]); + return ClassUtils.toClassArray(this.interfaces); } @Override diff --git a/spring-aop/src/main/java/org/springframework/aop/support/DefaultIntroductionAdvisor.java b/spring-aop/src/main/java/org/springframework/aop/support/DefaultIntroductionAdvisor.java index 32af73dc7b..8219737a22 100644 --- a/spring-aop/src/main/java/org/springframework/aop/support/DefaultIntroductionAdvisor.java +++ b/spring-aop/src/main/java/org/springframework/aop/support/DefaultIntroductionAdvisor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2018 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. @@ -104,7 +104,7 @@ public class DefaultIntroductionAdvisor implements IntroductionAdvisor, ClassFil @Override public Class[] getInterfaces() { - return this.interfaces.toArray(new Class[this.interfaces.size()]); + return ClassUtils.toClassArray(this.interfaces); } @Override diff --git a/spring-aop/src/main/java/org/springframework/aop/support/IntroductionInfoSupport.java b/spring-aop/src/main/java/org/springframework/aop/support/IntroductionInfoSupport.java index b91c897502..b0153f91bb 100644 --- a/spring-aop/src/main/java/org/springframework/aop/support/IntroductionInfoSupport.java +++ b/spring-aop/src/main/java/org/springframework/aop/support/IntroductionInfoSupport.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2018 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. @@ -53,15 +53,15 @@ public class IntroductionInfoSupport implements IntroductionInfo, Serializable { * due to the delegate implementing it. Call this method to exclude * internal interfaces from being visible at the proxy level. *

Does nothing if the interface is not implemented by the delegate. - * @param intf the interface to suppress + * @param ifc the interface to suppress */ - public void suppressInterface(Class intf) { - this.publishedInterfaces.remove(intf); + public void suppressInterface(Class ifc) { + this.publishedInterfaces.remove(ifc); } @Override public Class[] getInterfaces() { - return this.publishedInterfaces.toArray(new Class[this.publishedInterfaces.size()]); + return ClassUtils.toClassArray(this.publishedInterfaces); } /** diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java index cf7d8de329..4101865e3b 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java @@ -1742,7 +1742,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto if (targetType != null && targetType != obj.getClass()) { sources.add(targetType); } - return sources.toArray(new Object[sources.size()]); + return sources.toArray(); } private RootBeanDefinition getRootBeanDefinition(String beanName) { diff --git a/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/KeyGeneratorAdapter.java b/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/KeyGeneratorAdapter.java index 42db86cefd..4c6bccb2c1 100644 --- a/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/KeyGeneratorAdapter.java +++ b/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/KeyGeneratorAdapter.java @@ -1,3 +1,19 @@ +/* + * Copyright 2002-2018 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.springframework.cache.jcache.interceptor; import java.lang.annotation.Annotation; @@ -13,10 +29,9 @@ import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; /** - * Spring's {@link KeyGenerator} implementation that either delegates to a - * standard JSR-107 {@link javax.cache.annotation.CacheKeyGenerator}, or - * wrap a standard {@link KeyGenerator} so that only relevant parameters - * are handled. + * Spring's {@link KeyGenerator} implementation that either delegates to a standard JSR-107 + * {@link javax.cache.annotation.CacheKeyGenerator}, or wrap a standard {@link KeyGenerator} + * so that only relevant parameters are handled. * * @author Stephane Nicoll * @since 4.1 @@ -29,12 +44,13 @@ class KeyGeneratorAdapter implements KeyGenerator { private CacheKeyGenerator cacheKeyGenerator; + /** * Create an instance with the given {@link KeyGenerator} so that {@link javax.cache.annotation.CacheKey} * and {@link javax.cache.annotation.CacheValue} are handled according to the spec. */ public KeyGeneratorAdapter(JCacheOperationSource cacheOperationSource, KeyGenerator target) { - Assert.notNull(cacheOperationSource, "cacheOperationSource must not be null."); + Assert.notNull(cacheOperationSource, "JCacheOperationSource must not be null"); Assert.notNull(target, "KeyGenerator must not be null"); this.cacheOperationSource = cacheOperationSource; this.keyGenerator = target; @@ -44,12 +60,13 @@ class KeyGeneratorAdapter implements KeyGenerator { * Create an instance used to wrap the specified {@link javax.cache.annotation.CacheKeyGenerator}. */ public KeyGeneratorAdapter(JCacheOperationSource cacheOperationSource, CacheKeyGenerator target) { - Assert.notNull(cacheOperationSource, "cacheOperationSource must not be null."); - Assert.notNull(target, "KeyGenerator must not be null"); + Assert.notNull(cacheOperationSource, "JCacheOperationSource must not be null"); + Assert.notNull(target, "CacheKeyGenerator must not be null"); this.cacheOperationSource = cacheOperationSource; this.cacheKeyGenerator = target; } + /** * Return the target key generator to use in the form of either a {@link KeyGenerator} * or a {@link CacheKeyGenerator}. @@ -58,7 +75,6 @@ class KeyGeneratorAdapter implements KeyGenerator { return (this.keyGenerator != null ? this.keyGenerator : this.cacheKeyGenerator); } - @Override public Object generate(Object target, Method method, Object... params) { JCacheOperation operation = this.cacheOperationSource.getCacheOperation(method, target.getClass()); @@ -88,15 +104,14 @@ class KeyGeneratorAdapter implements KeyGenerator { parameters.add(value); } } - return keyGenerator.generate(context.getTarget(), context.getMethod(), - parameters.toArray(new Object[parameters.size()])); - + return keyGenerator.generate(context.getTarget(), context.getMethod(), parameters.toArray()); } @SuppressWarnings("unchecked") - private CacheKeyInvocationContext createCacheKeyInvocationContext(Object target, - JCacheOperation operation, Object[] params) { + private CacheKeyInvocationContext createCacheKeyInvocationContext( + Object target, JCacheOperation operation, Object[] params) { + AbstractJCacheKeyOperation keyCacheOperation = (AbstractJCacheKeyOperation) operation; return new DefaultCacheKeyInvocationContext(keyCacheOperation, target, params); } diff --git a/spring-context/src/main/java/org/springframework/context/support/AbstractMessageSource.java b/spring-context/src/main/java/org/springframework/context/support/AbstractMessageSource.java index 5e1414e074..53bf01e46f 100644 --- a/spring-context/src/main/java/org/springframework/context/support/AbstractMessageSource.java +++ b/spring-context/src/main/java/org/springframework/context/support/AbstractMessageSource.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 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. @@ -330,7 +330,7 @@ public abstract class AbstractMessageSource extends MessageSourceSupport impleme resolvedArgs.add(arg); } } - return resolvedArgs.toArray(new Object[resolvedArgs.size()]); + return resolvedArgs.toArray(); } /** diff --git a/spring-context/src/main/java/org/springframework/validation/beanvalidation/SpringValidatorAdapter.java b/spring-context/src/main/java/org/springframework/validation/beanvalidation/SpringValidatorAdapter.java index 7d6b8f759b..61561beb83 100644 --- a/spring-context/src/main/java/org/springframework/validation/beanvalidation/SpringValidatorAdapter.java +++ b/spring-context/src/main/java/org/springframework/validation/beanvalidation/SpringValidatorAdapter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 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. @@ -17,9 +17,9 @@ package org.springframework.validation.beanvalidation; import java.io.Serializable; +import java.util.ArrayList; import java.util.HashSet; import java.util.LinkedHashSet; -import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Set; @@ -34,6 +34,7 @@ import org.springframework.beans.NotReadablePropertyException; import org.springframework.context.MessageSourceResolvable; import org.springframework.context.support.DefaultMessageSourceResolvable; import org.springframework.util.Assert; +import org.springframework.util.ClassUtils; import org.springframework.validation.BindingResult; import org.springframework.validation.Errors; import org.springframework.validation.FieldError; @@ -115,7 +116,7 @@ public class SpringValidatorAdapter implements SmartValidator, javax.validation. } } processConstraintViolations( - this.targetValidator.validate(target, groups.toArray(new Class[groups.size()])), errors); + this.targetValidator.validate(target, ClassUtils.toClassArray(groups)), errors); } } @@ -215,7 +216,7 @@ public class SpringValidatorAdapter implements SmartValidator, javax.validation. * @see org.springframework.validation.DefaultBindingErrorProcessor#getArgumentsForBindError */ protected Object[] getArgumentsForConstraint(String objectName, String field, ConstraintDescriptor descriptor) { - List arguments = new LinkedList(); + List arguments = new ArrayList(); arguments.add(getResolvableField(objectName, field)); // Using a TreeMap for alphabetical ordering of attribute names Map attributesToExpose = new TreeMap(); @@ -230,7 +231,7 @@ public class SpringValidatorAdapter implements SmartValidator, javax.validation. } } arguments.addAll(attributesToExpose.values()); - return arguments.toArray(new Object[arguments.size()]); + return arguments.toArray(); } /** diff --git a/spring-core/src/main/java/org/springframework/util/ClassUtils.java b/spring-core/src/main/java/org/springframework/util/ClassUtils.java index 5a99de2ea3..07481ed13b 100644 --- a/spring-core/src/main/java/org/springframework/util/ClassUtils.java +++ b/spring-core/src/main/java/org/springframework/util/ClassUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 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. @@ -1064,11 +1064,12 @@ public abstract class ClassUtils { } /** - * Copy the given Collection into a Class array. - * The Collection must contain Class elements only. - * @param collection the Collection to copy - * @return the Class array ({@code null} if the passed-in - * Collection was {@code null}) + * Copy the given {@code Collection} into a {@code Class} array. + *

The {@code Collection} must contain {@code Class} elements only. + * @param collection the {@code Collection} to copy + * @return the {@code Class} array + * @since 3.1 + * @see StringUtils#toStringArray */ public static Class[] toClassArray(Collection> collection) { if (collection == null) { @@ -1109,8 +1110,7 @@ public abstract class ClassUtils { * @return all interfaces that the given object implements as an array */ public static Class[] getAllInterfacesForClass(Class clazz, ClassLoader classLoader) { - Set> ifcs = getAllInterfacesForClassAsSet(clazz, classLoader); - return ifcs.toArray(new Class[ifcs.size()]); + return toClassArray(getAllInterfacesForClassAsSet(clazz, classLoader)); } /** @@ -1150,12 +1150,13 @@ public abstract class ClassUtils { return Collections.>singleton(clazz); } Set> interfaces = new LinkedHashSet>(); - while (clazz != null) { - Class[] ifcs = clazz.getInterfaces(); + Class current = clazz; + while (current != null) { + Class[] ifcs = current.getInterfaces(); for (Class ifc : ifcs) { interfaces.addAll(getAllInterfacesForClassAsSet(ifc, classLoader)); } - clazz = clazz.getSuperclass(); + current = current.getSuperclass(); } return interfaces; } diff --git a/spring-core/src/main/java/org/springframework/util/StringUtils.java b/spring-core/src/main/java/org/springframework/util/StringUtils.java index 5e2fbfec15..8b61bc01d3 100644 --- a/spring-core/src/main/java/org/springframework/util/StringUtils.java +++ b/spring-core/src/main/java/org/springframework/util/StringUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 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. @@ -824,13 +824,9 @@ public abstract class StringUtils { return array1; } - List result = new ArrayList(); + Set result = new LinkedHashSet(); result.addAll(Arrays.asList(array1)); - for (String str : array2) { - if (!result.contains(str)) { - result.add(str); - } - } + result.addAll(Arrays.asList(array2)); return toStringArray(result); } @@ -858,7 +854,6 @@ public abstract class StringUtils { if (collection == null) { return null; } - return collection.toArray(new String[collection.size()]); } @@ -872,9 +867,7 @@ public abstract class StringUtils { if (enumeration == null) { return null; } - - List list = Collections.list(enumeration); - return list.toArray(new String[list.size()]); + return toStringArray(Collections.list(enumeration)); } /** @@ -939,10 +932,9 @@ public abstract class StringUtils { /** * Take an array of strings and split each element based on the given delimiter. - * A {@code Properties} instance is then generated, with the left of the - * delimiter providing the key, and the right of the delimiter providing the value. - *

Will trim both the key and value before adding them to the - * {@code Properties} instance. + * A {@code Properties} instance is then generated, with the left of the delimiter + * providing the key, and the right of the delimiter providing the value. + *

Will trim both the key and value before adding them to the {@code Properties}. * @param array the array to process * @param delimiter to split each element using (typically the equals symbol) * @return a {@code Properties} instance representing the array contents, diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/simple/AbstractJdbcInsert.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/simple/AbstractJdbcInsert.java index 3d7c25f1d3..43c6acaf05 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/simple/AbstractJdbcInsert.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/simple/AbstractJdbcInsert.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 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. @@ -458,15 +458,18 @@ public abstract class AbstractJdbcInsert { "Current database only supports retrieving the key for a single column. There are " + getGeneratedKeyNames().length + " columns specified: " + Arrays.asList(getGeneratedKeyNames())); } - // This is a hack to be able to get the generated key from a database that doesn't support - // get generated keys feature. HSQL is one, PostgreSQL is another. Postgres uses a RETURNING - // clause while HSQL uses a second query that has to be executed with the same connection. + final String keyQuery = this.tableMetaDataContext.getSimulationQueryForGetGeneratedKey( this.tableMetaDataContext.getTableName(), getGeneratedKeyNames()[0]); Assert.notNull(keyQuery, "Query for simulating get generated keys can't be null"); + + // This is a hack to be able to get the generated key from a database that doesn't support + // get generated keys feature. HSQL is one, PostgreSQL is another. Postgres uses a RETURNING + // clause while HSQL uses a second query that has to be executed with the same connection. + if (keyQuery.toUpperCase().startsWith("RETURNING")) { - Long key = getJdbcTemplate().queryForObject(getInsertString() + " " + keyQuery, - values.toArray(new Object[values.size()]), Long.class); + Long key = getJdbcTemplate().queryForObject( + getInsertString() + " " + keyQuery, values.toArray(), Long.class); Map keys = new HashMap(1); keys.put(getGeneratedKeyNames()[0], key); keyHolder.getKeyList().add(keys); @@ -506,8 +509,8 @@ public abstract class AbstractJdbcInsert { } }); } - return keyHolder; } + return keyHolder; } diff --git a/spring-jms/src/main/java/org/springframework/jms/connection/CachingConnectionFactory.java b/spring-jms/src/main/java/org/springframework/jms/connection/CachingConnectionFactory.java index ffccdc87e3..cefded9da6 100644 --- a/spring-jms/src/main/java/org/springframework/jms/connection/CachingConnectionFactory.java +++ b/spring-jms/src/main/java/org/springframework/jms/connection/CachingConnectionFactory.java @@ -265,10 +265,8 @@ public class CachingConnectionFactory extends SingleConnectionFactory { if (target instanceof TopicSession) { classes.add(TopicSession.class); } - return (Session) Proxy.newProxyInstance( - SessionProxy.class.getClassLoader(), - classes.toArray(new Class[classes.size()]), - new CachedSessionInvocationHandler(target, sessionList)); + return (Session) Proxy.newProxyInstance(SessionProxy.class.getClassLoader(), + ClassUtils.toClassArray(classes), new CachedSessionInvocationHandler(target, sessionList)); } diff --git a/spring-jms/src/main/java/org/springframework/jms/connection/SingleConnectionFactory.java b/spring-jms/src/main/java/org/springframework/jms/connection/SingleConnectionFactory.java index 453a0249f4..ad00340101 100644 --- a/spring-jms/src/main/java/org/springframework/jms/connection/SingleConnectionFactory.java +++ b/spring-jms/src/main/java/org/springframework/jms/connection/SingleConnectionFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 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. @@ -40,6 +40,7 @@ import org.apache.commons.logging.LogFactory; import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.InitializingBean; import org.springframework.util.Assert; +import org.springframework.util.ClassUtils; /** * A JMS ConnectionFactory adapter that returns the same Connection @@ -481,10 +482,8 @@ public class SingleConnectionFactory implements ConnectionFactory, QueueConnecti if (target instanceof TopicConnection) { classes.add(TopicConnection.class); } - return (Connection) Proxy.newProxyInstance( - Connection.class.getClassLoader(), - classes.toArray(new Class[classes.size()]), - new SharedConnectionInvocationHandler()); + return (Connection) Proxy.newProxyInstance(Connection.class.getClassLoader(), + ClassUtils.toClassArray(classes), new SharedConnectionInvocationHandler()); } diff --git a/spring-jms/src/main/java/org/springframework/jms/connection/TransactionAwareConnectionFactoryProxy.java b/spring-jms/src/main/java/org/springframework/jms/connection/TransactionAwareConnectionFactoryProxy.java index 928297cb62..e08c2a1bc6 100644 --- a/spring-jms/src/main/java/org/springframework/jms/connection/TransactionAwareConnectionFactoryProxy.java +++ b/spring-jms/src/main/java/org/springframework/jms/connection/TransactionAwareConnectionFactoryProxy.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 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. @@ -35,6 +35,7 @@ import javax.jms.TopicSession; import javax.jms.TransactionInProgressException; import org.springframework.util.Assert; +import org.springframework.util.ClassUtils; /** * Proxy for a target JMS {@link javax.jms.ConnectionFactory}, adding awareness of @@ -204,10 +205,8 @@ public class TransactionAwareConnectionFactoryProxy if (target instanceof TopicConnection) { classes.add(TopicConnection.class); } - return (Connection) Proxy.newProxyInstance( - Connection.class.getClassLoader(), - classes.toArray(new Class[classes.size()]), - new TransactionAwareConnectionInvocationHandler(target)); + return (Connection) Proxy.newProxyInstance(Connection.class.getClassLoader(), + ClassUtils.toClassArray(classes), new TransactionAwareConnectionInvocationHandler(target)); } @@ -276,10 +275,8 @@ public class TransactionAwareConnectionFactoryProxy if (target instanceof TopicSession) { classes.add(TopicSession.class); } - return (Session) Proxy.newProxyInstance( - SessionProxy.class.getClassLoader(), - classes.toArray(new Class[classes.size()]), - new CloseSuppressingSessionInvocationHandler(target)); + return (Session) Proxy.newProxyInstance(SessionProxy.class.getClassLoader(), + ClassUtils.toClassArray(classes), new CloseSuppressingSessionInvocationHandler(target)); } } diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/AbstractEntityManagerFactoryBean.java b/spring-orm/src/main/java/org/springframework/orm/jpa/AbstractEntityManagerFactoryBean.java index 3c672e25a1..6cb02ea4a5 100644 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/AbstractEntityManagerFactoryBean.java +++ b/spring-orm/src/main/java/org/springframework/orm/jpa/AbstractEntityManagerFactoryBean.java @@ -395,11 +395,11 @@ public abstract class AbstractEntityManagerFactoryBean implements } /** - * Create a proxy of the given EntityManagerFactory. We do this to be able - * to return transaction-aware proxies for application-managed - * EntityManagers, and to introduce the NamedEntityManagerFactory interface - * @param emf EntityManagerFactory as returned by the persistence provider - * @return proxy entity manager + * Create a proxy for the given {@link EntityManagerFactory}. We do this to be able to + * return a transaction-aware proxy for an application-managed {@link EntityManager}. + * @param emf the EntityManagerFactory as returned by the persistence provider, + * if initialized already + * @return the EntityManagerFactory proxy */ protected EntityManagerFactory createEntityManagerFactoryProxy(EntityManagerFactory emf) { Set> ifcs = new LinkedHashSet>(); @@ -415,9 +415,8 @@ public abstract class AbstractEntityManagerFactoryBean implements } ifcs.add(EntityManagerFactoryInfo.class); try { - return (EntityManagerFactory) Proxy.newProxyInstance( - this.beanClassLoader, ifcs.toArray(new Class[ifcs.size()]), - new ManagedEntityManagerFactoryInvocationHandler(this)); + return (EntityManagerFactory) Proxy.newProxyInstance(this.beanClassLoader, + ClassUtils.toClassArray(ifcs), new ManagedEntityManagerFactoryInvocationHandler(this)); } catch (IllegalArgumentException ex) { if (entityManagerFactoryInterface != null) { @@ -608,9 +607,8 @@ public abstract class AbstractEntityManagerFactoryBean implements /** - * Dynamic proxy invocation handler proxying an EntityManagerFactory to - * return a proxy EntityManager if necessary from createEntityManager() - * methods. + * Dynamic proxy invocation handler for an {@link EntityManagerFactory}, returning a + * proxy {@link EntityManager} (if necessary) from {@code createEntityManager} methods. */ @SuppressWarnings("serial") private static class ManagedEntityManagerFactoryInvocationHandler implements InvocationHandler, Serializable { diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/ExtendedEntityManagerCreator.java b/spring-orm/src/main/java/org/springframework/orm/jpa/ExtendedEntityManagerCreator.java index 1575a7d2f0..c3b83b14b4 100644 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/ExtendedEntityManagerCreator.java +++ b/spring-orm/src/main/java/org/springframework/orm/jpa/ExtendedEntityManagerCreator.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 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. @@ -231,7 +231,7 @@ public abstract class ExtendedEntityManagerCreator { ifcs.add(EntityManagerProxy.class); return (EntityManager) Proxy.newProxyInstance( (cl != null ? cl : ExtendedEntityManagerCreator.class.getClassLoader()), - ifcs.toArray(new Class[ifcs.size()]), + ClassUtils.toClassArray(ifcs), new ExtendedEntityManagerInvocationHandler( rawEm, exceptionTranslator, jta, containerManaged, synchronizedWithTransaction)); } @@ -427,6 +427,7 @@ public abstract class ExtendedEntityManagerCreator { public ExtendedEntityManagerSynchronization( EntityManager em, PersistenceExceptionTranslator exceptionTranslator) { + super(new EntityManagerHolder(em), em); this.entityManager = em; this.exceptionTranslator = exceptionTranslator; diff --git a/spring-oxm/src/main/java/org/springframework/oxm/jaxb/ClassPathJaxb2TypeScanner.java b/spring-oxm/src/main/java/org/springframework/oxm/jaxb/ClassPathJaxb2TypeScanner.java index 6c6af3e919..dfaed8c515 100644 --- a/spring-oxm/src/main/java/org/springframework/oxm/jaxb/ClassPathJaxb2TypeScanner.java +++ b/spring-oxm/src/main/java/org/springframework/oxm/jaxb/ClassPathJaxb2TypeScanner.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2018 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. @@ -92,7 +92,7 @@ class ClassPathJaxb2TypeScanner { } } } - return jaxb2Classes.toArray(new Class[jaxb2Classes.size()]); + return ClassUtils.toClassArray(jaxb2Classes); } catch (IOException ex) { throw new UncategorizedMappingException("Failed to scan classpath for unlisted classes", ex); diff --git a/spring-test/src/main/java/org/springframework/test/context/support/AnnotationConfigContextLoaderUtils.java b/spring-test/src/main/java/org/springframework/test/context/support/AnnotationConfigContextLoaderUtils.java index 968d2300e8..a9ea561020 100644 --- a/spring-test/src/main/java/org/springframework/test/context/support/AnnotationConfigContextLoaderUtils.java +++ b/spring-test/src/main/java/org/springframework/test/context/support/AnnotationConfigContextLoaderUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 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 org.springframework.context.annotation.Configuration; import org.springframework.core.annotation.AnnotatedElementUtils; import org.springframework.test.context.SmartContextLoader; import org.springframework.util.Assert; +import org.springframework.util.ClassUtils; /** * Utility methods for {@link SmartContextLoader SmartContextLoaders} that deal @@ -84,7 +85,7 @@ public abstract class AnnotationConfigContextLoaderUtils { } } - return configClasses.toArray(new Class[configClasses.size()]); + return ClassUtils.toClassArray(configClasses); } /** diff --git a/spring-web/src/main/java/org/springframework/web/context/support/AnnotationConfigWebApplicationContext.java b/spring-web/src/main/java/org/springframework/web/context/support/AnnotationConfigWebApplicationContext.java index a7be81ad6c..189e97df1b 100644 --- a/spring-web/src/main/java/org/springframework/web/context/support/AnnotationConfigWebApplicationContext.java +++ b/spring-web/src/main/java/org/springframework/web/context/support/AnnotationConfigWebApplicationContext.java @@ -28,6 +28,7 @@ import org.springframework.context.annotation.AnnotationConfigUtils; import org.springframework.context.annotation.ClassPathBeanDefinitionScanner; import org.springframework.context.annotation.ScopeMetadataResolver; import org.springframework.util.Assert; +import org.springframework.util.ClassUtils; import org.springframework.util.StringUtils; import org.springframework.web.context.ContextLoader; @@ -207,7 +208,7 @@ public class AnnotationConfigWebApplicationContext extends AbstractRefreshableWe logger.info("Registering annotated classes: [" + StringUtils.collectionToCommaDelimitedString(this.annotatedClasses) + "]"); } - reader.register(this.annotatedClasses.toArray(new Class[this.annotatedClasses.size()])); + reader.register(ClassUtils.toClassArray(this.annotatedClasses)); } if (!this.basePackages.isEmpty()) { diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerMapping.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerMapping.java index 474d16baff..0ecab435b4 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerMapping.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerMapping.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 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. @@ -329,7 +329,7 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport * @return the array of {@link MappedInterceptor}s, or {@code null} if none */ protected final MappedInterceptor[] getMappedInterceptors() { - List mappedInterceptors = new ArrayList(); + List mappedInterceptors = new ArrayList(this.adaptedInterceptors.size()); for (HandlerInterceptor interceptor : this.adaptedInterceptors) { if (interceptor instanceof MappedInterceptor) { mappedInterceptors.add((MappedInterceptor) interceptor); diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/WebMvcStompWebSocketEndpointRegistration.java b/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/WebMvcStompWebSocketEndpointRegistration.java index 2d5bf37b3d..a0a307b1f3 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/WebMvcStompWebSocketEndpointRegistration.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/WebMvcStompWebSocketEndpointRegistration.java @@ -73,7 +73,6 @@ public class WebMvcStompWebSocketEndpointRegistration implements StompWebSocketE @Override public StompWebSocketEndpointRegistration setHandshakeHandler(HandshakeHandler handshakeHandler) { - Assert.notNull(handshakeHandler, "'handshakeHandler' must not be null"); this.handshakeHandler = handshakeHandler; return this; } @@ -113,7 +112,7 @@ public class WebMvcStompWebSocketEndpointRegistration implements StompWebSocketE } protected HandshakeInterceptor[] getInterceptors() { - List interceptors = new ArrayList(); + List interceptors = new ArrayList(this.interceptors.size() + 1); interceptors.addAll(this.interceptors); interceptors.add(new OriginHandshakeInterceptor(this.allowedOrigins)); return interceptors.toArray(new HandshakeInterceptor[interceptors.size()]); @@ -124,7 +123,7 @@ public class WebMvcStompWebSocketEndpointRegistration implements StompWebSocketE if (this.registration != null) { SockJsService sockJsService = this.registration.getSockJsService(); for (String path : this.paths) { - String pattern = path.endsWith("/") ? path + "**" : path + "/**"; + String pattern = (path.endsWith("/") ? path + "**" : path + "/**"); SockJsHttpRequestHandler handler = new SockJsHttpRequestHandler(sockJsService, this.webSocketHandler); mappings.add(handler, pattern); }