Skip to content

Commit 901ced7

Browse files
committed
Polishing
1 parent 8a48c5a commit 901ced7

File tree

19 files changed

+135
-104
lines changed

19 files changed

+135
-104
lines changed

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

Lines changed: 6 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.
@@ -54,8 +54,9 @@ public interface InstantiationAwareBeanPostProcessor extends BeanPostProcessor {
5454
* will be short-circuited. The only further processing applied is the
5555
* {@link #postProcessAfterInitialization} callback from the configured
5656
* {@link BeanPostProcessor BeanPostProcessors}.
57-
* <p>This callback will only be applied to bean definitions with a bean class.
58-
* In particular, it will not be applied to beans with a factory method.
57+
* <p>This callback will be applied to bean definitions with their bean class,
58+
* as well as to factory-method definitions in which case the returned bean type
59+
* will be passed in here.
5960
* <p>Post-processors may implement the extended
6061
* {@link SmartInstantiationAwareBeanPostProcessor} interface in order
6162
* to predict the type of the bean object that they are going to return here.
@@ -66,7 +67,8 @@ public interface InstantiationAwareBeanPostProcessor extends BeanPostProcessor {
6667
* or {@code null} to proceed with default instantiation
6768
* @throws org.springframework.beans.BeansException in case of errors
6869
* @see #postProcessAfterInstantiation
69-
* @see org.springframework.beans.factory.support.AbstractBeanDefinition#hasBeanClass
70+
* @see org.springframework.beans.factory.support.AbstractBeanDefinition#getBeanClass()
71+
* @see org.springframework.beans.factory.support.AbstractBeanDefinition#getFactoryMethodName()
7072
*/
7173
@Nullable
7274
default Object postProcessBeforeInstantiation(Class<?> beanClass, String beanName) throws BeansException {

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-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.
@@ -85,10 +85,12 @@ public boolean match(MetadataReader metadataReader, MetadataReaderFactory metada
8585
}
8686
}
8787
catch (IOException ex) {
88-
logger.debug("Could not read super class [" + metadata.getSuperClassName() +
89-
"] of type-filtered class [" + metadata.getClassName() + "]");
88+
if (logger.isDebugEnabled()) {
89+
logger.debug("Could not read super class [" + metadata.getSuperClassName() +
90+
"] of type-filtered class [" + metadata.getClassName() + "]");
91+
}
9092
}
91-
}
93+
}
9294
}
9395
}
9496

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

spring-core/src/main/java/org/springframework/util/SerializationUtils.java

Lines changed: 3 additions & 5 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.
@@ -43,8 +43,7 @@ public static byte[] serialize(@Nullable Object object) {
4343
return null;
4444
}
4545
ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
46-
try {
47-
ObjectOutputStream oos = new ObjectOutputStream(baos);
46+
try (ObjectOutputStream oos = new ObjectOutputStream(baos)) {
4847
oos.writeObject(object);
4948
oos.flush();
5049
}
@@ -64,8 +63,7 @@ public static Object deserialize(@Nullable byte[] bytes) {
6463
if (bytes == null) {
6564
return null;
6665
}
67-
try {
68-
ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(bytes));
66+
try (ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(bytes))) {
6967
return ois.readObject();
7068
}
7169
catch (IOException ex) {

spring-core/src/test/java/org/springframework/util/SerializationTestUtils.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2013 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.
@@ -34,8 +34,9 @@ public class SerializationTestUtils {
3434

3535
public static void testSerialization(Object o) throws IOException {
3636
OutputStream baos = new ByteArrayOutputStream();
37-
ObjectOutputStream oos = new ObjectOutputStream(baos);
38-
oos.writeObject(o);
37+
try (ObjectOutputStream oos = new ObjectOutputStream(baos)) {
38+
oos.writeObject(o);
39+
}
3940
}
4041

4142
public static boolean isSerializable(Object o) throws IOException {
@@ -50,16 +51,17 @@ public static boolean isSerializable(Object o) throws IOException {
5051

5152
public static Object serializeAndDeserialize(Object o) throws IOException, ClassNotFoundException {
5253
ByteArrayOutputStream baos = new ByteArrayOutputStream();
53-
ObjectOutputStream oos = new ObjectOutputStream(baos);
54-
oos.writeObject(o);
55-
oos.flush();
54+
try (ObjectOutputStream oos = new ObjectOutputStream(baos)) {
55+
oos.writeObject(o);
56+
oos.flush();
57+
}
5658
baos.flush();
5759
byte[] bytes = baos.toByteArray();
5860

5961
ByteArrayInputStream is = new ByteArrayInputStream(bytes);
60-
ObjectInputStream ois = new ObjectInputStream(is);
61-
Object o2 = ois.readObject();
62-
return o2;
62+
try (ObjectInputStream ois = new ObjectInputStream(is)) {
63+
return ois.readObject();
64+
}
6365
}
6466

6567
}

spring-jdbc/src/main/java/org/springframework/jdbc/datasource/embedded/AbstractEmbeddedDatabaseConfigurer.java

Lines changed: 6 additions & 3 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.
@@ -18,6 +18,7 @@
1818

1919
import java.sql.Connection;
2020
import java.sql.SQLException;
21+
import java.sql.Statement;
2122
import javax.sql.DataSource;
2223

2324
import org.apache.commons.logging.Log;
@@ -42,11 +43,13 @@ public void shutdown(DataSource dataSource, String databaseName) {
4243
try {
4344
con = dataSource.getConnection();
4445
if (con != null) {
45-
con.createStatement().execute("SHUTDOWN");
46+
try (Statement stmt = con.createStatement()) {
47+
stmt.execute("SHUTDOWN");
48+
}
4649
}
4750
}
4851
catch (SQLException ex) {
49-
logger.warn("Could not shut down embedded database", ex);
52+
logger.info("Could not shut down embedded database", ex);
5053
}
5154
finally {
5255
if (con != null) {

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

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 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.
@@ -66,20 +66,23 @@ public static CustomSQLExceptionTranslatorRegistry getInstance() {
6666
private CustomSQLExceptionTranslatorRegistry() {
6767
}
6868

69+
6970
/**
7071
* Register a new custom translator for the specified database name.
7172
* @param dbName the database name
7273
* @param translator the custom translator
7374
*/
7475
public void registerTranslator(String dbName, SQLExceptionTranslator translator) {
75-
SQLExceptionTranslator replaced = translatorMap.put(dbName, translator);
76-
if (replaced != null) {
77-
logger.warn("Replacing custom translator [" + replaced + "] for database '" + dbName +
78-
"' with [" + translator + "]");
79-
}
80-
else {
81-
logger.info("Adding custom translator of type [" + translator.getClass().getName() +
82-
"] for database '" + dbName + "'");
76+
SQLExceptionTranslator replaced = this.translatorMap.put(dbName, translator);
77+
if (logger.isDebugEnabled()) {
78+
if (replaced != null) {
79+
logger.debug("Replacing custom translator [" + replaced + "] for database '" + dbName +
80+
"' with [" + translator + "]");
81+
}
82+
else {
83+
logger.debug("Adding custom translator of type [" + translator.getClass().getName() +
84+
"] for database '" + dbName + "'");
85+
}
8386
}
8487
}
8588

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: 4 additions & 4 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.
@@ -41,7 +41,6 @@
4141
* @since 16.05.2003
4242
* @see org.springframework.transaction.support.TransactionTemplate
4343
* @see org.springframework.transaction.interceptor.TransactionInterceptor
44-
* @see org.springframework.transaction.interceptor.TransactionProxyFactoryBean
4544
*/
4645
public interface PlatformTransactionManager {
4746

@@ -56,7 +55,7 @@ public interface PlatformTransactionManager {
5655
* <p>An exception to the above rule is the read-only flag, which should be
5756
* ignored if no explicit read-only mode is supported. Essentially, the
5857
* read-only flag is just a hint for potential optimization.
59-
* @param definition TransactionDefinition instance (can be {@code null} for defaults),
58+
* @param definition the TransactionDefinition instance (can be {@code null} for defaults),
6059
* describing propagation behavior, isolation level, timeout etc.
6160
* @return transaction status object representing the new or current transaction
6261
* @throws TransactionException in case of lookup, creation, or system errors
@@ -68,7 +67,8 @@ public interface PlatformTransactionManager {
6867
* @see TransactionDefinition#getTimeout
6968
* @see TransactionDefinition#isReadOnly
7069
*/
71-
TransactionStatus getTransaction(@Nullable TransactionDefinition definition) throws TransactionException;
70+
TransactionStatus getTransaction(@Nullable TransactionDefinition definition)
71+
throws TransactionException;
7272

7373
/**
7474
* Commit the given transaction, with regard to its status. If the transaction

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: 9 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.
@@ -101,7 +101,7 @@ public abstract class TransactionAspectSupport implements BeanFactoryAware, Init
101101
* <p>To find out about specific transaction characteristics, consider using
102102
* TransactionSynchronizationManager's {@code isSynchronizationActive()}
103103
* and/or {@code isActualTransactionActive()} methods.
104-
* @return TransactionInfo bound to this thread, or {@code null} if none
104+
* @return the TransactionInfo bound to this thread, or {@code null} if none
105105
* @see TransactionInfo#hasTransaction()
106106
* @see org.springframework.transaction.support.TransactionSynchronizationManager#isSynchronizationActive()
107107
* @see org.springframework.transaction.support.TransactionSynchronizationManager#isActualTransactionActive()
@@ -287,7 +287,8 @@ protected Object invokeWithinTransaction(Method method, @Nullable Class<?> targe
287287
if (txAttr == null || !(tm instanceof CallbackPreferringPlatformTransactionManager)) {
288288
// Standard transaction demarcation with getTransaction and commit/rollback calls.
289289
TransactionInfo txInfo = createTransactionIfNecessary(tm, txAttr, joinpointIdentification);
290-
Object retVal = null;
290+
291+
Object retVal;
291292
try {
292293
// This is an around advice: Invoke the next interceptor in the chain.
293294
// This will normally result in a target object being invoked.
@@ -507,9 +508,10 @@ protected TransactionInfo prepareTransactionInfo(@Nullable PlatformTransactionMa
507508
else {
508509
// The TransactionInfo.hasTransaction() method will return false. We created it only
509510
// to preserve the integrity of the ThreadLocal stack maintained in this class.
510-
if (logger.isTraceEnabled())
511-
logger.trace("Don't need to create transaction for [" + joinpointIdentification +
512-
"]: This method isn't transactional.");
511+
if (logger.isTraceEnabled()) {
512+
logger.trace("No need to create transaction for [" + joinpointIdentification +
513+
"]: This method is not transactional.");
514+
}
513515
}
514516

515517
// We always bind the TransactionInfo to the thread, even if we didn't create
@@ -591,7 +593,7 @@ protected void cleanupTransactionInfo(@Nullable TransactionInfo txInfo) {
591593

592594

593595
/**
594-
* Opaque object used to hold Transaction information. Subclasses
596+
* Opaque object used to hold transaction information. Subclasses
595597
* must pass it back to methods on this class, but not see its internals.
596598
*/
597599
protected final class TransactionInfo {

0 commit comments

Comments
 (0)