From d5e45927280f84d44eaa869b238b2cc61b7a4a7a Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Sun, 2 Nov 2014 11:19:54 +0100 Subject: [PATCH] Polishing --- .../NoSuchBeanDefinitionException.java | 12 +++--- .../support/DefaultListableBeanFactory.java | 6 +-- .../expression/spel/SpelReproTests.java | 41 +++++++++---------- .../DelegatingConnectionFactory.java | 4 +- .../connection/SingleConnectionFactory.java | 11 ++--- .../web/util/Log4jWebConfigurer.java | 3 +- ...ildcardServletTilesApplicationContext.java | 15 ++++--- .../SpringTilesApplicationContextFactory.java | 6 +-- 8 files changed, 48 insertions(+), 50 deletions(-) diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/NoSuchBeanDefinitionException.java b/spring-beans/src/main/java/org/springframework/beans/factory/NoSuchBeanDefinitionException.java index 5bd8ea7a9f..106fa0cafc 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/NoSuchBeanDefinitionException.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/NoSuchBeanDefinitionException.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2014 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,21 +20,23 @@ import org.springframework.beans.BeansException; import org.springframework.util.StringUtils; /** - * Exception thrown when a {@code BeanFactory} is asked for a bean instance - * for which it cannot find a definition. + * Exception thrown when a {@code BeanFactory} is asked for a bean instance for which it + * cannot find a definition. This may point to a non-existing bean, a non-unique bean, + * or a manually registered singleton instance without an associated bean definition. * * @author Rod Johnson * @author Juergen Hoeller * @see BeanFactory#getBean(String) * @see BeanFactory#getBean(Class) + * @see NoUniqueBeanDefinitionException */ @SuppressWarnings("serial") public class NoSuchBeanDefinitionException extends BeansException { - /** Name of the missing bean. */ + /** Name of the missing bean */ private String beanName; - /** Required type of the missing bean. */ + /** Required type of the missing bean */ private Class beanType; 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 067773ee70..3823dd7008 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 @@ -135,14 +135,14 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto /** Map of bean definition objects, keyed by bean name */ private final Map beanDefinitionMap = new ConcurrentHashMap(64); - /** Map of singleton and non-singleton bean names keyed by dependency type */ + /** Map of singleton and non-singleton bean names, keyed by dependency type */ private final Map, String[]> allBeanNamesByType = new ConcurrentHashMap, String[]>(64); - /** Map of singleton-only bean names keyed by dependency type */ + /** Map of singleton-only bean names, keyed by dependency type */ private final Map, String[]> singletonBeanNamesByType = new ConcurrentHashMap, String[]>(64); /** List of bean definition names, in registration order */ - private final List beanDefinitionNames = new ArrayList(); + private final List beanDefinitionNames = new ArrayList(64); /** Whether bean definition metadata may be cached for all beans */ private boolean configurationFrozen = false; diff --git a/spring-expression/src/test/java/org/springframework/expression/spel/SpelReproTests.java b/spring-expression/src/test/java/org/springframework/expression/spel/SpelReproTests.java index 124bdb55e2..202f31ea7c 100644 --- a/spring-expression/src/test/java/org/springframework/expression/spel/SpelReproTests.java +++ b/spring-expression/src/test/java/org/springframework/expression/spel/SpelReproTests.java @@ -1847,21 +1847,21 @@ public class SpelReproTests extends ExpressionTestCase { private boolean primitiveProperty = true; - public Boolean isSimpleProperty() { - return simpleProperty; - } - public void setSimpleProperty(Boolean simpleProperty) { this.simpleProperty = simpleProperty; } - public boolean isPrimitiveProperty() { - return primitiveProperty; + public Boolean isSimpleProperty() { + return this.simpleProperty; } public void setPrimitiveProperty(boolean primitiveProperty) { this.primitiveProperty = primitiveProperty; } + + public boolean isPrimitiveProperty() { + return this.primitiveProperty; + } } @@ -1914,13 +1914,13 @@ public class SpelReproTests extends ExpressionTestCase { private String name = "name"; - public String getName() { - return name; - } - public void setName(String name) { this.name = name; } + + public String getName() { + return this.name; + } } @@ -1932,25 +1932,22 @@ public class SpelReproTests extends ExpressionTestCase { } - static class TestClass2 { // SPR-9194 + static class TestClass2 { // SPR-9194 String string; - public TestClass2(String string) { this.string = string; } - @Override - public int hashCode() { - return 0; + public boolean equals(Object other) { + return (this == other || (other instanceof TestClass2 && + this.string.equals(((TestClass2) other).string))); } - public boolean equals(Object o) { - if (o instanceof TestClass2) { - return string.equals(((TestClass2) o).string); - } - return false; + @Override + public int hashCode() { + return this.string.hashCode(); } } @@ -1964,12 +1961,12 @@ public class SpelReproTests extends ExpressionTestCase { } public int parameter() { - return counter.incrementAndGet(); + return this.counter.incrementAndGet(); } @Override public Object resolve(EvaluationContext context, String beanName) throws AccessException { - return beanName.equals("bean") ? this : null; + return (beanName.equals("bean") ? this : null); } } diff --git a/spring-jms/src/main/java/org/springframework/jms/connection/DelegatingConnectionFactory.java b/spring-jms/src/main/java/org/springframework/jms/connection/DelegatingConnectionFactory.java index e01bfec1f0..04d26aa1b5 100644 --- a/spring-jms/src/main/java/org/springframework/jms/connection/DelegatingConnectionFactory.java +++ b/spring-jms/src/main/java/org/springframework/jms/connection/DelegatingConnectionFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2014 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. @@ -76,7 +76,7 @@ public class DelegatingConnectionFactory /** * Indicate whether Connections obtained from the target factory are supposed * to be stopped before closed ("true") or simply closed ("false"). - * The latter may be necessary for some connection pools that simply return + * An extra stop call may be necessary for some connection pools that simply return * released connections to the pool, not stopping them while they sit in the pool. *

Default is "false", simply closing Connections. * @see ConnectionFactoryUtils#releaseConnection 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 17e7bbd569..619e38f86e 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 @@ -73,9 +73,8 @@ import org.springframework.util.Assert; * @see org.springframework.jms.listener.SimpleMessageListenerContainer * @see org.springframework.jms.listener.DefaultMessageListenerContainer#setCacheLevel */ -public class SingleConnectionFactory - implements ConnectionFactory, QueueConnectionFactory, TopicConnectionFactory, ExceptionListener, - InitializingBean, DisposableBean { +public class SingleConnectionFactory implements ConnectionFactory, QueueConnectionFactory, + TopicConnectionFactory, ExceptionListener, InitializingBean, DisposableBean { protected final Log logger = LogFactory.getLog(getClass()); @@ -171,7 +170,7 @@ public class SingleConnectionFactory /** * Specify an JMS ExceptionListener implementation that should be - * registered with with the single Connection created by this factory. + * registered with the single Connection created by this factory. * @see #setReconnectOnException */ public void setExceptionListener(ExceptionListener exceptionListener) { @@ -180,7 +179,7 @@ public class SingleConnectionFactory /** * Return the JMS ExceptionListener implementation that should be registered - * with with the single Connection created by this factory, if any. + * with the single Connection created by this factory, if any. */ protected ExceptionListener getExceptionListener() { return this.exceptionListener; @@ -307,6 +306,7 @@ public class SingleConnectionFactory * The provider of this ConnectionFactory needs to care for proper shutdown. *

As this bean implements DisposableBean, a bean factory will * automatically invoke this on destruction of its cached singletons. + * @see #resetConnection() */ public void destroy() { resetConnection(); @@ -314,6 +314,7 @@ public class SingleConnectionFactory /** * Reset the underlying shared Connection, to be reinitialized on next access. + * @see #closeConnection */ public void resetConnection() { synchronized (this.connectionMonitor) { diff --git a/spring-web/src/main/java/org/springframework/web/util/Log4jWebConfigurer.java b/spring-web/src/main/java/org/springframework/web/util/Log4jWebConfigurer.java index 4861703930..5fe7a6ae09 100644 --- a/spring-web/src/main/java/org/springframework/web/util/Log4jWebConfigurer.java +++ b/spring-web/src/main/java/org/springframework/web/util/Log4jWebConfigurer.java @@ -127,8 +127,7 @@ public abstract class Log4jWebConfigurer { // Leave a URL (e.g. "classpath:" or "file:") as-is. if (!ResourceUtils.isUrl(location)) { - // Consider a plain file path as relative to the web - // application root directory. + // Consider a plain file path as relative to the web application root directory. location = WebUtils.getRealPath(servletContext, location); } diff --git a/spring-webmvc-tiles3/src/main/java/org/springframework/web/servlet/view/tiles3/SpringWildcardServletTilesApplicationContext.java b/spring-webmvc-tiles3/src/main/java/org/springframework/web/servlet/view/tiles3/SpringWildcardServletTilesApplicationContext.java index e79fe8d5dd..e75e5891ec 100644 --- a/spring-webmvc-tiles3/src/main/java/org/springframework/web/servlet/view/tiles3/SpringWildcardServletTilesApplicationContext.java +++ b/spring-webmvc-tiles3/src/main/java/org/springframework/web/servlet/view/tiles3/SpringWildcardServletTilesApplicationContext.java @@ -30,6 +30,7 @@ import org.apache.tiles.request.servlet.ServletApplicationContext; import org.springframework.core.io.Resource; import org.springframework.core.io.support.ResourcePatternResolver; +import org.springframework.util.CollectionUtils; import org.springframework.util.ObjectUtils; import org.springframework.web.context.support.ServletContextResourcePatternResolver; @@ -53,22 +54,20 @@ public class SpringWildcardServletTilesApplicationContext extends ServletApplica @Override public ApplicationResource getResource(String localePath) { - ApplicationResource retValue = null; Collection urlSet = getResources(localePath); - if (urlSet != null && !urlSet.isEmpty()) { - retValue = urlSet.iterator().next(); + if (!CollectionUtils.isEmpty(urlSet)) { + return urlSet.iterator().next(); } - return retValue; + return null; } @Override public ApplicationResource getResource(ApplicationResource base, Locale locale) { - ApplicationResource retValue = null; Collection urlSet = getResources(base.getLocalePath(locale)); - if (urlSet != null && !urlSet.isEmpty()) { - retValue = urlSet.iterator().next(); + if (!CollectionUtils.isEmpty(urlSet)) { + return urlSet.iterator().next(); } - return retValue; + return null; } @Override diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/tiles2/SpringTilesApplicationContextFactory.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/tiles2/SpringTilesApplicationContextFactory.java index 59a2e633da..3162cc9cd8 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/tiles2/SpringTilesApplicationContextFactory.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/tiles2/SpringTilesApplicationContextFactory.java @@ -49,6 +49,7 @@ public class SpringTilesApplicationContextFactory extends AbstractTilesApplicati private Map params; + public void init(Map params) { this.params = params; } @@ -89,12 +90,11 @@ public class SpringTilesApplicationContextFactory extends AbstractTilesApplicati @Override public URL getResource(String path) throws IOException { - URL retValue = null; Set urlSet = getResources(path); if (!CollectionUtils.isEmpty(urlSet)) { - retValue = urlSet.iterator().next(); + return urlSet.iterator().next(); } - return retValue; + return null; } @Override