Polishing

This commit is contained in:
Juergen Hoeller
2018-07-20 16:45:17 +02:00
parent 5007d01c17
commit c3f6403f61
19 changed files with 80 additions and 63 deletions

View File

@@ -651,7 +651,7 @@ public class ProxyFactoryBean extends ProxyCreatorSupport
}
public String getBeanName() {
return beanName;
return this.beanName;
}
@Override

View File

@@ -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.
@@ -74,8 +74,8 @@ public abstract class AbstractPrototypeBasedTargetSource extends AbstractBeanFac
* @param target the bean instance to destroy
*/
protected void destroyPrototypeInstance(Object target) {
if (this.logger.isDebugEnabled()) {
this.logger.debug("Destroying instance of bean '" + getTargetBeanName() + "'");
if (logger.isDebugEnabled()) {
logger.debug("Destroying instance of bean '" + getTargetBeanName() + "'");
}
if (getBeanFactory() instanceof ConfigurableBeanFactory) {
((ConfigurableBeanFactory) getBeanFactory()).destroyBean(getTargetBeanName(), target);
@@ -85,7 +85,7 @@ public abstract class AbstractPrototypeBasedTargetSource extends AbstractBeanFac
((DisposableBean) target).destroy();
}
catch (Throwable ex) {
logger.error("Couldn't invoke destroy method of bean with name '" + getTargetBeanName() + "'", ex);
logger.error("Destroy method on bean with name '" + getTargetBeanName() + "' threw an exception", ex);
}
}
}

View File

@@ -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.
@@ -248,12 +248,12 @@ class DisposableBeanAdapter implements DisposableBean, Runnable, Serializable {
try {
if (System.getSecurityManager() != null) {
AccessController.doPrivileged((PrivilegedExceptionAction<Object>) () -> {
((DisposableBean) bean).destroy();
((DisposableBean) this.bean).destroy();
return null;
}, acc);
}, this.acc);
}
else {
((DisposableBean) bean).destroy();
((DisposableBean) this.bean).destroy();
}
}
catch (Throwable ex) {
@@ -326,7 +326,7 @@ class DisposableBeanAdapter implements DisposableBean, Runnable, Serializable {
});
try {
AccessController.doPrivileged((PrivilegedExceptionAction<Object>) () ->
destroyMethod.invoke(bean, args), acc);
destroyMethod.invoke(this.bean, args), this.acc);
}
catch (PrivilegedActionException pax) {
throw (InvocationTargetException) pax.getException();
@@ -334,12 +334,12 @@ class DisposableBeanAdapter implements DisposableBean, Runnable, Serializable {
}
else {
ReflectionUtils.makeAccessible(destroyMethod);
destroyMethod.invoke(bean, args);
destroyMethod.invoke(this.bean, args);
}
}
catch (InvocationTargetException ex) {
String msg = "Invocation of destroy method '" + this.destroyMethodName +
"' failed on bean with name '" + this.beanName + "'";
String msg = "Destroy method '" + this.destroyMethodName + "' on bean with name '" +
this.beanName + "' threw an exception";
if (logger.isDebugEnabled()) {
logger.warn(msg, ex.getTargetException());
}
@@ -348,7 +348,7 @@ class DisposableBeanAdapter implements DisposableBean, Runnable, Serializable {
}
}
catch (Throwable ex) {
logger.error("Couldn't invoke destroy method '" + this.destroyMethodName +
logger.error("Failed to invoke destroy method '" + this.destroyMethodName +
"' on bean with name '" + this.beanName + "'", ex);
}
}

View File

@@ -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.
@@ -77,7 +77,7 @@ public class AutoProxyRegistrar implements ImportBeanDefinitionRegistrar {
}
}
}
if (!candidateFound) {
if (!candidateFound && logger.isWarnEnabled()) {
String name = getClass().getSimpleName();
logger.warn(String.format("%s was imported but no annotations were found " +
"having both 'mode' and 'proxyTargetClass' attributes of type " +

View File

@@ -151,7 +151,9 @@ public class MBeanRegistrationSupport {
registeredBean = this.server.registerMBean(mbean, objectName);
}
catch (InstanceNotFoundException ex2) {
logger.error("Unable to replace existing MBean at [" + objectName + "]", ex2);
if (logger.isErrorEnabled()) {
logger.error("Unable to replace existing MBean at [" + objectName + "]", ex2);
}
throw ex;
}
}
@@ -181,9 +183,9 @@ public class MBeanRegistrationSupport {
}
if (!snapshot.isEmpty()) {
logger.info("Unregistering JMX-exposed beans");
}
for (ObjectName objectName : snapshot) {
doUnregister(objectName);
for (ObjectName objectName : snapshot) {
doUnregister(objectName);
}
}
}

View File

@@ -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.
@@ -436,8 +436,8 @@ public class RmiServiceExporter extends RmiBasedExporter implements Initializing
}
catch (NotBoundException ex) {
if (logger.isWarnEnabled()) {
logger.warn("RMI service '" + this.serviceName + "' is not bound to registry"
+ (this.createdRegistry ? (" at port '" + this.registryPort + "' anymore") : ""), ex);
logger.warn("RMI service '" + this.serviceName + "' is not bound to registry" +
(this.createdRegistry ? (" at port '" + this.registryPort + "' anymore") : ""), ex);
}
}
finally {
@@ -454,8 +454,9 @@ public class RmiServiceExporter extends RmiBasedExporter implements Initializing
}
catch (NoSuchObjectException ex) {
if (logger.isWarnEnabled()) {
logger.warn("RMI object for service '" + this.serviceName + "' isn't exported anymore", ex);
logger.warn("RMI object for service '" + this.serviceName + "' is not exported anymore", ex);
}
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2007 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.
@@ -79,13 +79,13 @@ public abstract class RemoteInvocationBasedExporter extends RemoteExporter {
}
catch (NoSuchMethodException ex) {
if (logger.isDebugEnabled()) {
logger.warn("Could not find target method for " + invocation, ex);
logger.debug("Could not find target method for " + invocation, ex);
}
throw ex;
}
catch (IllegalAccessException ex) {
if (logger.isDebugEnabled()) {
logger.warn("Could not access target method for " + invocation, ex);
logger.debug("Could not access target method for " + invocation, ex);
}
throw ex;
}

View File

@@ -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.
@@ -157,7 +157,7 @@ public class ScheduledExecutorFactoryBean extends ExecutorConfigurationSupport
((ScheduledThreadPoolExecutor) executor).setRemoveOnCancelPolicy(true);
}
else {
logger.info("Could not apply remove-on-cancel policy - not a Java 7+ ScheduledThreadPoolExecutor");
logger.info("Could not apply remove-on-cancel policy - not a ScheduledThreadPoolExecutor");
}
}

View File

@@ -99,7 +99,7 @@ public class ThreadPoolTaskScheduler extends ExecutorConfigurationSupport
((ScheduledThreadPoolExecutor) this.scheduledExecutor).setRemoveOnCancelPolicy(removeOnCancelPolicy);
}
else if (removeOnCancelPolicy && this.scheduledExecutor != null) {
logger.info("Could not apply remove-on-cancel policy - not a Java 7+ ScheduledThreadPoolExecutor");
logger.info("Could not apply remove-on-cancel policy - not a ScheduledThreadPoolExecutor");
}
}
@@ -122,7 +122,7 @@ public class ThreadPoolTaskScheduler extends ExecutorConfigurationSupport
((ScheduledThreadPoolExecutor) this.scheduledExecutor).setRemoveOnCancelPolicy(true);
}
else {
logger.info("Could not apply remove-on-cancel policy - not a Java 7+ ScheduledThreadPoolExecutor");
logger.info("Could not apply remove-on-cancel policy - not a ScheduledThreadPoolExecutor");
}
}
@@ -284,8 +284,8 @@ public class ThreadPoolTaskScheduler extends ExecutorConfigurationSupport
private void executeAndTrack(ExecutorService executor, ListenableFutureTask<?> listenableFuture) {
Future<?> scheduledFuture = executor.submit(errorHandlingTask(listenableFuture, false));
this.listenableFutureMap.put(scheduledFuture, listenableFuture);
listenableFuture.addCallback(result -> listenableFutureMap.remove(scheduledFuture),
ex -> listenableFutureMap.remove(scheduledFuture));
listenableFuture.addCallback(result -> this.listenableFutureMap.remove(scheduledFuture),
ex -> this.listenableFutureMap.remove(scheduledFuture));
}
@Override
@@ -403,8 +403,8 @@ public class ThreadPoolTaskScheduler extends ExecutorConfigurationSupport
try {
return this.delegate.call();
}
catch (Throwable t) {
this.errorHandler.handleError(t);
catch (Throwable ex) {
this.errorHandler.handleError(ex);
return null;
}
}

View File

@@ -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,6 +17,7 @@
package org.springframework.core.env;
import java.security.AccessControlException;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.Map;
@@ -250,6 +251,9 @@ public abstract class AbstractEnvironment implements ConfigurableEnvironment {
@Override
public void setActiveProfiles(String... profiles) {
Assert.notNull(profiles, "Profile array must not be null");
if (logger.isDebugEnabled()) {
logger.debug("Activating profiles " + Arrays.asList(profiles));
}
synchronized (this.activeProfiles) {
this.activeProfiles.clear();
for (String profile : profiles) {

View File

@@ -520,7 +520,7 @@ public class CallMetaDataContext {
matchedParameters.put(parameterName,
SqlParameterSourceUtils.getTypedValue(parameterSource, sourceName));
}
else {
else if (logger.isWarnEnabled()) {
logger.warn("Unable to locate the corresponding parameter value for '" +
parameterName + "' within the parameter values provided: " +
caseInsensitiveParameterNames.values());
@@ -587,7 +587,7 @@ public class CallMetaDataContext {
for (String parameterName : callParameterNames.keySet()) {
String parameterNameToMatch = provider.parameterNameToUse(parameterName);
String callParameterName = callParameterNames.get(lowerCase(parameterNameToMatch));
if (!matchedParameters.containsKey(callParameterName)) {
if (!matchedParameters.containsKey(callParameterName) && logger.isWarnEnabled()) {
logger.warn("Unable to locate the corresponding parameter value for '" + parameterName +
"' within the parameter values provided: " + inParameters.keySet());
}

View File

@@ -264,7 +264,7 @@ public class TableMetaDataContext {
/**
* Build the insert string based on configuration and meta-data information
* Build the insert string based on configuration and meta-data information.
* @return the insert string to be used
*/
public String createInsertString(String... generatedKeyNames) {
@@ -293,8 +293,10 @@ public class TableMetaDataContext {
insertStatement.append(") VALUES(");
if (columnCount < 1) {
if (this.generatedKeyColumnsUsed) {
logger.info("Unable to locate non-key columns for table '" +
getTableName() + "' so an empty insert statement is generated");
if (logger.isInfoEnabled()) {
logger.info("Unable to locate non-key columns for table '" +
getTableName() + "' so an empty insert statement is generated");
}
}
else {
throw new InvalidDataAccessApiUsageException("Unable to locate columns for table '" +
@@ -360,6 +362,9 @@ public class TableMetaDataContext {
}
/**
* Does this database support a simple query to retrieve generated keys
* when the JDBC 3.0 feature is not supported:
* {@link java.sql.DatabaseMetaData#supportsGetGeneratedKeys()}?
* @deprecated as of 4.3.15, in favor of {@link #getSimpleQueryForGetGeneratedKey}
*/
@Deprecated

View File

@@ -91,8 +91,8 @@ public class EmbeddedDatabaseFactory {
* generation of a pseudo-random unique ID to be used as the database name.
* <p>Setting this flag to {@code true} overrides any explicit name set
* via {@link #setDatabaseName}.
* @see #setDatabaseName
* @since 4.2
* @see #setDatabaseName
*/
public void setGenerateUniqueDatabaseName(boolean generateUniqueDatabaseName) {
this.generateUniqueDatabaseName = generateUniqueDatabaseName;
@@ -187,7 +187,7 @@ public class EmbeddedDatabaseFactory {
if (this.dataSource instanceof SimpleDriverDataSource) {
SimpleDriverDataSource simpleDriverDataSource = (SimpleDriverDataSource) this.dataSource;
logger.info(String.format("Starting embedded database: url='%s', username='%s'",
simpleDriverDataSource.getUrl(), simpleDriverDataSource.getUsername()));
simpleDriverDataSource.getUrl(), simpleDriverDataSource.getUsername()));
}
else {
logger.info(String.format("Starting embedded database '%s'", this.databaseName));

View File

@@ -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.
@@ -124,8 +124,8 @@ public class SQLErrorCodesFactory {
// Check all beans of type SQLErrorCodes.
errorCodes = lbf.getBeansOfType(SQLErrorCodes.class, true, false);
if (logger.isInfoEnabled()) {
logger.info("SQLErrorCodes loaded: " + errorCodes.keySet());
if (logger.isDebugEnabled()) {
logger.debug("SQLErrorCodes loaded: " + errorCodes.keySet());
}
}
catch (BeansException ex) {

View File

@@ -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.
@@ -188,7 +188,7 @@ public class TemporaryLobCreator implements LobCreator {
}
}
catch (SQLException ex) {
logger.error("Could not free LOB", ex);
logger.error("Could not free LOBs", ex);
}
}

View File

@@ -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.
@@ -26,7 +26,7 @@ import org.springframework.messaging.MessageHeaders;
import org.springframework.util.StringUtils;
/**
* A base {@link HeaderMapper} implementation
* A base {@link HeaderMapper} implementation.
*
* @author Stephane Nicoll
* @since 4.1

View File

@@ -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.
@@ -218,7 +218,8 @@ public class JibxMarshaller extends AbstractMarshaller implements InitializingBe
if (this.targetClass != null) {
if (StringUtils.hasLength(this.bindingName)) {
if (logger.isInfoEnabled()) {
logger.info("Configured for target class [" + this.targetClass + "] using binding [" + this.bindingName + "]");
logger.info("Configured for target class [" + this.targetClass +
"] using binding [" + this.bindingName + "]");
}
this.bindingFactory = BindingDirectory.getFactory(this.bindingName, this.targetClass);
}
@@ -230,11 +231,12 @@ public class JibxMarshaller extends AbstractMarshaller implements InitializingBe
}
}
else if (this.targetPackage != null) {
if (!StringUtils.hasLength(bindingName)) {
bindingName = DEFAULT_BINDING_NAME;
if (!StringUtils.hasLength(this.bindingName)) {
this.bindingName = DEFAULT_BINDING_NAME;
}
if (logger.isInfoEnabled()) {
logger.info("Configured for target package [" + this.targetPackage + "] using binding [" + this.bindingName + "]");
logger.info("Configured for target package [" + this.targetPackage +
"] using binding [" + this.bindingName + "]");
}
this.bindingFactory = BindingDirectory.getFactory(this.bindingName, this.targetPackage);
}
@@ -290,9 +292,10 @@ public class JibxMarshaller extends AbstractMarshaller implements InitializingBe
}
private void marshalDocument(IMarshallingContext marshallingContext, Object graph) throws IOException, JiBXException {
if (StringUtils.hasLength(docTypeRootElementName)) {
if (StringUtils.hasLength(this.docTypeRootElementName)) {
IXMLWriter xmlWriter = marshallingContext.getXmlWriter();
xmlWriter.writeDocType(docTypeRootElementName, docTypeSystemId, docTypePublicId, docTypeInternalSubset);
xmlWriter.writeDocType(this.docTypeRootElementName, this.docTypeSystemId,
this.docTypePublicId, this.docTypeInternalSubset);
}
marshallingContext.marshalDocument(graph);
}
@@ -391,7 +394,7 @@ public class JibxMarshaller extends AbstractMarshaller implements InitializingBe
protected Object unmarshalInputStream(InputStream inputStream) throws XmlMappingException, IOException {
try {
IUnmarshallingContext unmarshallingContext = createUnmarshallingContext();
return unmarshallingContext.unmarshalDocument(inputStream, encoding);
return unmarshallingContext.unmarshalDocument(inputStream, this.encoding);
}
catch (JiBXException ex) {
throw convertJibxException(ex, false);

View File

@@ -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.
@@ -76,7 +76,9 @@ public class WebSocketAnnotationMethodMessageHandler extends SimpAnnotationMetho
AnnotationExceptionHandlerMethodResolver resolver = new AnnotationExceptionHandlerMethodResolver(type);
if (resolver.hasExceptionMappings()) {
registerExceptionHandlerAdvice(bean, resolver);
logger.info("Detected @MessageExceptionHandler methods in " + bean);
if (logger.isInfoEnabled()) {
logger.info("Detected @MessageExceptionHandler methods in " + bean);
}
}
}
}

View File

@@ -145,9 +145,9 @@ public class ServerEndpointExporter extends WebApplicationObjectSupport
ServerContainer serverContainer = getServerContainer();
Assert.state(serverContainer != null,
"No ServerContainer set. Most likely the server's own WebSocket ServletContainerInitializer " +
"has not run yet. Was the Spring ApplicationContext refreshed through a " +
"org.springframework.web.context.ContextLoaderListener, " +
"i.e. after the ServletContext has been fully initialized?");
"has not run yet. Was the Spring ApplicationContext refreshed through a " +
"org.springframework.web.context.ContextLoaderListener, " +
"i.e. after the ServletContext has been fully initialized?");
try {
if (logger.isInfoEnabled()) {
logger.info("Registering @ServerEndpoint class: " + endpointClass);