Skip to content

Commit 1f4ca61

Browse files
committed
Polishing
1 parent 2e7489d commit 1f4ca61

File tree

13 files changed

+92
-67
lines changed

13 files changed

+92
-67
lines changed

spring-beans/src/main/java/org/springframework/beans/factory/config/InstantiationAwareBeanPostProcessor.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -53,8 +53,9 @@ public interface InstantiationAwareBeanPostProcessor extends BeanPostProcessor {
5353
* will be short-circuited. The only further processing applied is the
5454
* {@link #postProcessAfterInitialization} callback from the configured
5555
* {@link BeanPostProcessor BeanPostProcessors}.
56-
* <p>This callback will only be applied to bean definitions with a bean class.
57-
* In particular, it will not be applied to beans with a "factory-method".
56+
* <p>This callback will be applied to bean definitions with their bean class,
57+
* as well as to factory-method definitions in which case the returned bean type
58+
* will be passed in here.
5859
* <p>Post-processors may implement the extended
5960
* {@link SmartInstantiationAwareBeanPostProcessor} interface in order
6061
* to predict the type of the bean object that they are going to return here.
@@ -63,8 +64,9 @@ public interface InstantiationAwareBeanPostProcessor extends BeanPostProcessor {
6364
* @return the bean object to expose instead of a default instance of the target bean,
6465
* or {@code null} to proceed with default instantiation
6566
* @throws org.springframework.beans.BeansException in case of errors
66-
* @see org.springframework.beans.factory.support.AbstractBeanDefinition#hasBeanClass
67-
* @see org.springframework.beans.factory.support.AbstractBeanDefinition#getFactoryMethodName
67+
* @see #postProcessAfterInstantiation
68+
* @see org.springframework.beans.factory.support.AbstractBeanDefinition#getBeanClass()
69+
* @see org.springframework.beans.factory.support.AbstractBeanDefinition#getFactoryMethodName()
6870
*/
6971
Object postProcessBeforeInstantiation(Class<?> beanClass, String beanName) throws BeansException;
7072

@@ -80,6 +82,7 @@ public interface InstantiationAwareBeanPostProcessor extends BeanPostProcessor {
8082
* Returning {@code false} will also prevent any subsequent InstantiationAwareBeanPostProcessor
8183
* instances being invoked on this bean instance.
8284
* @throws org.springframework.beans.BeansException in case of errors
85+
* @see #postProcessBeforeInstantiation
8386
*/
8487
boolean postProcessAfterInstantiation(Object bean, String beanName) throws BeansException;
8588

@@ -95,9 +98,8 @@ public interface InstantiationAwareBeanPostProcessor extends BeanPostProcessor {
9598
* dependency types - which the factory handles specifically - already filtered out)
9699
* @param bean the bean instance created, but whose properties have not yet been set
97100
* @param beanName the name of the bean
98-
* @return the actual property values to apply to the given bean
99-
* (can be the passed-in PropertyValues instance), or {@code null}
100-
* to skip property population
101+
* @return the actual property values to apply to the given bean (can be the passed-in
102+
* PropertyValues instance), or {@code null} to skip property population
101103
* @throws org.springframework.beans.BeansException in case of errors
102104
* @see org.springframework.beans.MutablePropertyValues
103105
*/

spring-core/src/main/java/org/springframework/core/type/filter/AbstractTypeHierarchyTraversingFilter.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -83,10 +83,12 @@ public boolean match(MetadataReader metadataReader, MetadataReaderFactory metada
8383
}
8484
}
8585
catch (IOException ex) {
86-
logger.debug("Could not read super class [" + metadata.getSuperClassName() +
87-
"] of type-filtered class [" + metadata.getClassName() + "]");
86+
if (logger.isDebugEnabled()) {
87+
logger.debug("Could not read super class [" + metadata.getSuperClassName() +
88+
"] of type-filtered class [" + metadata.getClassName() + "]");
89+
}
8890
}
89-
}
91+
}
9092
}
9193
}
9294

@@ -107,8 +109,10 @@ public boolean match(MetadataReader metadataReader, MetadataReaderFactory metada
107109
}
108110
}
109111
catch (IOException ex) {
110-
logger.debug("Could not read interface [" + ifc + "] for type-filtered class [" +
111-
metadata.getClassName() + "]");
112+
if (logger.isDebugEnabled()) {
113+
logger.debug("Could not read interface [" + ifc + "] for type-filtered class [" +
114+
metadata.getClassName() + "]");
115+
}
112116
}
113117
}
114118
}

spring-jdbc/src/main/java/org/springframework/jdbc/support/CustomSQLExceptionTranslatorRegistry.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -70,14 +70,16 @@ private CustomSQLExceptionTranslatorRegistry() {
7070
* @param translator the custom translator
7171
*/
7272
public void registerTranslator(String dbName, SQLExceptionTranslator translator) {
73-
SQLExceptionTranslator replaced = translatorMap.put(dbName, translator);
74-
if (replaced != null) {
75-
logger.warn("Replacing custom translator [" + replaced + "] for database '" + dbName +
76-
"' with [" + translator + "]");
77-
}
78-
else {
79-
logger.info("Adding custom translator of type [" + translator.getClass().getName() +
80-
"] for database '" + dbName + "'");
73+
SQLExceptionTranslator replaced = this.translatorMap.put(dbName, translator);
74+
if (logger.isInfoEnabled()) {
75+
if (replaced != null) {
76+
logger.info("Replacing custom translator [" + replaced + "] for database '" + dbName +
77+
"' with [" + translator + "]");
78+
}
79+
else {
80+
logger.info("Adding custom translator of type [" + translator.getClass().getName() +
81+
"] for database '" + dbName + "'");
82+
}
8183
}
8284
}
8385

spring-jms/src/main/java/org/springframework/jms/listener/endpoint/DefaultJmsActivationSpecFactory.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -85,7 +85,9 @@ protected Class<?> determineActivationSpecClass(ResourceAdapter adapter) {
8585
return adapter.getClass().getClassLoader().loadClass(specClassName);
8686
}
8787
catch (ClassNotFoundException ex) {
88-
logger.debug("No default <Provider>ActivationSpec class found: " + specClassName);
88+
if (logger.isDebugEnabled()) {
89+
logger.debug("No default <Provider>ActivationSpec class found: " + specClassName);
90+
}
8991
}
9092
}
9193

@@ -98,7 +100,9 @@ else if (adapterClassName.endsWith(RESOURCE_ADAPTER_IMPL_SUFFIX)){
98100
return adapter.getClass().getClassLoader().loadClass(specClassName);
99101
}
100102
catch (ClassNotFoundException ex) {
101-
logger.debug("No default <Provider>ActivationSpecImpl class found: " + specClassName);
103+
if (logger.isDebugEnabled()) {
104+
logger.debug("No default <Provider>ActivationSpecImpl class found: " + specClassName);
105+
}
102106
}
103107
}
104108

@@ -109,7 +113,9 @@ else if (adapterClassName.endsWith(RESOURCE_ADAPTER_IMPL_SUFFIX)){
109113
return adapter.getClass().getClassLoader().loadClass(specClassName);
110114
}
111115
catch (ClassNotFoundException ex) {
112-
logger.debug("No default ActivationSpecImpl class found in provider package: " + specClassName);
116+
if (logger.isDebugEnabled()) {
117+
logger.debug("No default ActivationSpecImpl class found in provider package: " + specClassName);
118+
}
113119
}
114120

115121
// ActivationSpecImpl class in "inbound" subpackage (WebSphere MQ 6.0.2.1)
@@ -118,7 +124,9 @@ else if (adapterClassName.endsWith(RESOURCE_ADAPTER_IMPL_SUFFIX)){
118124
return adapter.getClass().getClassLoader().loadClass(specClassName);
119125
}
120126
catch (ClassNotFoundException ex) {
121-
logger.debug("No default ActivationSpecImpl class found in inbound subpackage: " + specClassName);
127+
if (logger.isDebugEnabled()) {
128+
logger.debug("No default ActivationSpecImpl class found in inbound subpackage: " + specClassName);
129+
}
122130
}
123131

124132
throw new IllegalStateException("No ActivationSpec class defined - " +

spring-tx/src/main/java/org/springframework/transaction/PlatformTransactionManager.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -39,7 +39,6 @@
3939
* @since 16.05.2003
4040
* @see org.springframework.transaction.support.TransactionTemplate
4141
* @see org.springframework.transaction.interceptor.TransactionInterceptor
42-
* @see org.springframework.transaction.interceptor.TransactionProxyFactoryBean
4342
*/
4443
public interface PlatformTransactionManager {
4544

@@ -54,7 +53,7 @@ public interface PlatformTransactionManager {
5453
* <p>An exception to the above rule is the read-only flag, which should be
5554
* ignored if no explicit read-only mode is supported. Essentially, the
5655
* read-only flag is just a hint for potential optimization.
57-
* @param definition TransactionDefinition instance (can be {@code null} for defaults),
56+
* @param definition the TransactionDefinition instance (can be {@code null} for defaults),
5857
* describing propagation behavior, isolation level, timeout etc.
5958
* @return transaction status object representing the new or current transaction
6059
* @throws TransactionException in case of lookup, creation, or system errors

spring-tx/src/main/java/org/springframework/transaction/annotation/Propagation.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,11 @@ public enum Propagation {
8787

8888
/**
8989
* Execute within a nested transaction if a current transaction exists,
90-
* behave like {@code REQUIRED} else. There is no analogous feature in EJB.
90+
* behave like {@code REQUIRED} otherwise. There is no analogous feature in EJB.
9191
* <p>Note: Actual creation of a nested transaction will only work on specific
9292
* transaction managers. Out of the box, this only applies to the JDBC
93-
* DataSourceTransactionManager when working on a JDBC 3.0 driver.
94-
* Some JTA providers might support nested transactions as well.
93+
* DataSourceTransactionManager. Some JTA providers might support nested
94+
* transactions as well.
9595
* @see org.springframework.jdbc.datasource.DataSourceTransactionManager
9696
*/
9797
NESTED(TransactionDefinition.PROPAGATION_NESTED);

spring-tx/src/main/java/org/springframework/transaction/interceptor/TransactionAspectSupport.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -100,7 +100,7 @@ public abstract class TransactionAspectSupport implements BeanFactoryAware, Init
100100
* <p>To find out about specific transaction characteristics, consider using
101101
* TransactionSynchronizationManager's {@code isSynchronizationActive()}
102102
* and/or {@code isActualTransactionActive()} methods.
103-
* @return TransactionInfo bound to this thread, or {@code null} if none
103+
* @return the TransactionInfo bound to this thread, or {@code null} if none
104104
* @see TransactionInfo#hasTransaction()
105105
* @see org.springframework.transaction.support.TransactionSynchronizationManager#isSynchronizationActive()
106106
* @see org.springframework.transaction.support.TransactionSynchronizationManager#isActualTransactionActive()
@@ -275,7 +275,8 @@ protected Object invokeWithinTransaction(Method method, Class<?> targetClass, fi
275275
if (txAttr == null || !(tm instanceof CallbackPreferringPlatformTransactionManager)) {
276276
// Standard transaction demarcation with getTransaction and commit/rollback calls.
277277
TransactionInfo txInfo = createTransactionIfNecessary(tm, txAttr, joinpointIdentification);
278-
Object retVal = null;
278+
279+
Object retVal;
279280
try {
280281
// This is an around advice: Invoke the next interceptor in the chain.
281282
// This will normally result in a target object being invoked.
@@ -369,6 +370,7 @@ protected PlatformTransactionManager determineTransactionManager(TransactionAttr
369370
if (txAttr == null || this.beanFactory == null) {
370371
return getTransactionManager();
371372
}
373+
372374
String qualifier = txAttr.getQualifier();
373375
if (StringUtils.hasText(qualifier)) {
374376
return determineQualifiedTransactionManager(qualifier);
@@ -493,9 +495,10 @@ protected TransactionInfo prepareTransactionInfo(PlatformTransactionManager tm,
493495
else {
494496
// The TransactionInfo.hasTransaction() method will return false. We created it only
495497
// to preserve the integrity of the ThreadLocal stack maintained in this class.
496-
if (logger.isTraceEnabled())
497-
logger.trace("Don't need to create transaction for [" + joinpointIdentification +
498-
"]: This method isn't transactional.");
498+
if (logger.isTraceEnabled()) {
499+
logger.trace("No need to create transaction for [" + joinpointIdentification +
500+
"]: This method is not transactional.");
501+
}
499502
}
500503

501504
// We always bind the TransactionInfo to the thread, even if we didn't create
@@ -585,7 +588,7 @@ protected void cleanupTransactionInfo(TransactionInfo txInfo) {
585588

586589

587590
/**
588-
* Opaque object used to hold Transaction information. Subclasses
591+
* Opaque object used to hold transaction information. Subclasses
589592
* must pass it back to methods on this class, but not see its internals.
590593
*/
591594
protected final class TransactionInfo {

spring-tx/src/main/java/org/springframework/transaction/support/AbstractPlatformTransactionManager.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -560,7 +560,7 @@ protected int determineTimeout(TransactionDefinition definition) {
560560
if (definition.getTimeout() != TransactionDefinition.TIMEOUT_DEFAULT) {
561561
return definition.getTimeout();
562562
}
563-
return this.defaultTimeout;
563+
return getDefaultTimeout();
564564
}
565565

566566

@@ -682,7 +682,7 @@ private List<TransactionSynchronization> doSuspendSynchronization() {
682682
/**
683683
* Reactivate transaction synchronization for the current thread
684684
* and resume all given synchronizations.
685-
* @param suspendedSynchronizations List of TransactionSynchronization objects
685+
* @param suspendedSynchronizations a List of TransactionSynchronization objects
686686
*/
687687
private void doResumeSynchronization(List<TransactionSynchronization> suspendedSynchronizations) {
688688
TransactionSynchronizationManager.initSynchronization();
@@ -994,7 +994,7 @@ else if (!synchronizations.isEmpty()) {
994994
* given Spring TransactionSynchronization objects.
995995
* <p>To be called by this abstract manager itself, or by special implementations
996996
* of the {@code registerAfterCompletionWithExistingTransaction} callback.
997-
* @param synchronizations List of TransactionSynchronization objects
997+
* @param synchronizations a List of TransactionSynchronization objects
998998
* @param completionStatus the completion status according to the
999999
* constants in the TransactionSynchronization interface
10001000
* @see #registerAfterCompletionWithExistingTransaction(Object, java.util.List)
@@ -1244,7 +1244,7 @@ protected void doSetRollbackOnly(DefaultTransactionStatus status) throws Transac
12441244
* immediately, passing in "STATUS_UNKNOWN". This is the best we can do if there's no
12451245
* chance to determine the actual outcome of the outer transaction.
12461246
* @param transaction transaction object returned by {@code doGetTransaction}
1247-
* @param synchronizations List of TransactionSynchronization objects
1247+
* @param synchronizations a List of TransactionSynchronization objects
12481248
* @throws TransactionException in case of system errors
12491249
* @see #invokeAfterCompletion(java.util.List, int)
12501250
* @see TransactionSynchronization#afterCompletion(int)
@@ -1307,6 +1307,7 @@ private SuspendedResourcesHolder(Object suspendedResources) {
13071307
private SuspendedResourcesHolder(
13081308
Object suspendedResources, List<TransactionSynchronization> suspendedSynchronizations,
13091309
String name, boolean readOnly, Integer isolationLevel, boolean wasActive) {
1310+
13101311
this.suspendedResources = suspendedResources;
13111312
this.suspendedSynchronizations = suspendedSynchronizations;
13121313
this.name = name;

spring-tx/src/main/java/org/springframework/transaction/support/TransactionSynchronizationManager.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -287,10 +287,11 @@ public static void registerSynchronization(TransactionSynchronization synchroniz
287287
throws IllegalStateException {
288288

289289
Assert.notNull(synchronization, "TransactionSynchronization must not be null");
290-
if (!isSynchronizationActive()) {
290+
Set<TransactionSynchronization> synchs = synchronizations.get();
291+
if (synchs == null) {
291292
throw new IllegalStateException("Transaction synchronization is not active");
292293
}
293-
synchronizations.get().add(synchronization);
294+
synchs.add(synchronization);
294295
}
295296

296297
/**

spring-web/src/main/java/org/springframework/web/method/annotation/AbstractWebArgumentResolverAdapter.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -80,7 +80,9 @@ public boolean supportsParameter(MethodParameter parameter) {
8080
}
8181
catch (Exception ex) {
8282
// ignore (see class-level doc)
83-
logger.debug("Error in checking support for parameter [" + parameter + "], message: " + ex.getMessage());
83+
if (logger.isDebugEnabled()) {
84+
logger.debug("Error in checking support for parameter [" + parameter + "]: " + ex.getMessage());
85+
}
8486
return false;
8587
}
8688
}

spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerExceptionResolver.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -99,7 +99,6 @@ public void setMappedHandlerClasses(Class<?>... mappedHandlerClasses) {
9999
* <p>Default is no warn logging. Specify this setting to activate warn logging into a specific
100100
* category. Alternatively, override the {@link #logException} method for custom logging.
101101
* @see org.apache.commons.logging.LogFactory#getLog(String)
102-
* @see org.apache.log4j.Logger#getLogger(String)
103102
* @see java.util.logging.Logger#getLogger(String)
104103
*/
105104
public void setWarnLogCategory(String loggerName) {
@@ -131,11 +130,11 @@ public ModelAndView resolveException(
131130
prepareResponse(ex, response);
132131
ModelAndView result = doResolveException(request, response, handler, ex);
133132
if (result != null) {
134-
// Print warn message when warn logger is not enabled...
133+
// Print debug message when warn logger is not enabled.
135134
if (logger.isDebugEnabled() && (this.warnLogger == null || !this.warnLogger.isWarnEnabled())) {
136135
logger.debug("Resolved [" + ex + "]" + (result.isEmpty() ? "" : " to " + result));
137136
}
138-
// warnLogger with full stack trace (requires explicit config)
137+
// Explicitly configured warn logger in logException method.
139138
logException(ex, request);
140139
}
141140
return result;

0 commit comments

Comments
 (0)