Browse Source

Never use 'this.' when accessing loggers

Ensure that `this.` is never used when accessing loggers.

Issue: SPR-16968
pull/1868/head
Phillip Webb 6 years ago committed by Juergen Hoeller
parent
commit
9de3689f63
  1. 6
      spring-aop/src/main/java/org/springframework/aop/target/AbstractPrototypeBasedTargetSource.java
  2. 4
      spring-beans/src/main/java/org/springframework/beans/factory/parsing/FailFastProblemReporter.java
  3. 36
      spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java
  4. 6
      spring-context/src/main/java/org/springframework/remoting/support/SimpleHttpServerFactoryBean.java
  5. 2
      spring-core/src/main/java/org/springframework/core/SimpleAliasRegistry.java
  6. 6
      spring-core/src/main/java/org/springframework/util/CommonsLogWriter.java
  7. 4
      spring-jcl/src/main/java/org/apache/commons/logging/LogFactory.java
  8. 4
      spring-messaging/src/main/java/org/springframework/messaging/core/GenericMessagingTemplate.java
  9. 8
      spring-web/src/main/java/org/springframework/http/server/reactive/AbstractListenerReadPublisher.java
  10. 2
      spring-web/src/main/java/org/springframework/http/server/reactive/AbstractListenerWriteFlushProcessor.java
  11. 4
      spring-web/src/main/java/org/springframework/http/server/reactive/AbstractListenerWriteProcessor.java
  12. 8
      spring-web/src/main/java/org/springframework/http/server/reactive/ServletServerHttpResponse.java
  13. 6
      spring-web/src/main/java/org/springframework/remoting/jaxws/SimpleHttpServerJaxWsServiceExporter.java
  14. 18
      spring-webmvc/src/main/java/org/springframework/web/servlet/FrameworkServlet.java

6
spring-aop/src/main/java/org/springframework/aop/target/AbstractPrototypeBasedTargetSource.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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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 * @param target the bean instance to destroy
*/ */
protected void destroyPrototypeInstance(Object target) { protected void destroyPrototypeInstance(Object target) {
if (this.logger.isDebugEnabled()) { if (logger.isDebugEnabled()) {
this.logger.debug("Destroying instance of bean '" + getTargetBeanName() + "'"); logger.debug("Destroying instance of bean '" + getTargetBeanName() + "'");
} }
if (getBeanFactory() instanceof ConfigurableBeanFactory) { if (getBeanFactory() instanceof ConfigurableBeanFactory) {
((ConfigurableBeanFactory) getBeanFactory()).destroyBean(getTargetBeanName(), target); ((ConfigurableBeanFactory) getBeanFactory()).destroyBean(getTargetBeanName(), target);

4
spring-beans/src/main/java/org/springframework/beans/factory/parsing/FailFastProblemReporter.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2012 the original author or authors. * Copyright 2002-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -78,7 +78,7 @@ public class FailFastProblemReporter implements ProblemReporter {
*/ */
@Override @Override
public void warning(Problem problem) { public void warning(Problem problem) {
this.logger.warn(problem, problem.getRootCause()); logger.warn(problem, problem.getRootCause());
} }
} }

36
spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java

@ -440,8 +440,8 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
throw ex; throw ex;
} }
// Probably contains a placeholder: let's ignore it for type matching purposes. // Probably contains a placeholder: let's ignore it for type matching purposes.
if (this.logger.isDebugEnabled()) { if (logger.isDebugEnabled()) {
this.logger.debug("Ignoring bean class loading failure for bean '" + beanName + "'", ex); logger.debug("Ignoring bean class loading failure for bean '" + beanName + "'", ex);
} }
onSuppressedException(ex); onSuppressedException(ex);
} }
@ -450,8 +450,8 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
throw ex; throw ex;
} }
// Probably contains a placeholder: let's ignore it for type matching purposes. // Probably contains a placeholder: let's ignore it for type matching purposes.
if (this.logger.isDebugEnabled()) { if (logger.isDebugEnabled()) {
this.logger.debug("Ignoring unresolvable metadata in bean definition '" + beanName + "'", ex); logger.debug("Ignoring unresolvable metadata in bean definition '" + beanName + "'", ex);
} }
onSuppressedException(ex); onSuppressedException(ex);
} }
@ -521,8 +521,8 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
BeanCreationException bce = (BeanCreationException) rootCause; BeanCreationException bce = (BeanCreationException) rootCause;
String exBeanName = bce.getBeanName(); String exBeanName = bce.getBeanName();
if (exBeanName != null && isCurrentlyInCreation(exBeanName)) { if (exBeanName != null && isCurrentlyInCreation(exBeanName)) {
if (this.logger.isDebugEnabled()) { if (logger.isDebugEnabled()) {
this.logger.debug("Ignoring match to currently created bean '" + exBeanName + "': " + logger.debug("Ignoring match to currently created bean '" + exBeanName + "': " +
ex.getMessage()); ex.getMessage());
} }
onSuppressedException(ex); onSuppressedException(ex);
@ -680,8 +680,8 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
public BeanDefinition getBeanDefinition(String beanName) throws NoSuchBeanDefinitionException { public BeanDefinition getBeanDefinition(String beanName) throws NoSuchBeanDefinitionException {
BeanDefinition bd = this.beanDefinitionMap.get(beanName); BeanDefinition bd = this.beanDefinitionMap.get(beanName);
if (bd == null) { if (bd == null) {
if (this.logger.isTraceEnabled()) { if (logger.isTraceEnabled()) {
this.logger.trace("No bean named '" + beanName + "' found in " + this); logger.trace("No bean named '" + beanName + "' found in " + this);
} }
throw new NoSuchBeanDefinitionException(beanName); throw new NoSuchBeanDefinitionException(beanName);
} }
@ -725,8 +725,8 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
@Override @Override
public void preInstantiateSingletons() throws BeansException { public void preInstantiateSingletons() throws BeansException {
if (this.logger.isDebugEnabled()) { if (logger.isDebugEnabled()) {
this.logger.debug("Pre-instantiating singletons in " + this); logger.debug("Pre-instantiating singletons in " + this);
} }
// Iterate over a copy to allow for init methods which in turn register new bean definitions. // Iterate over a copy to allow for init methods which in turn register new bean definitions.
@ -813,22 +813,22 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
} }
else if (oldBeanDefinition.getRole() < beanDefinition.getRole()) { else if (oldBeanDefinition.getRole() < beanDefinition.getRole()) {
// e.g. was ROLE_APPLICATION, now overriding with ROLE_SUPPORT or ROLE_INFRASTRUCTURE // e.g. was ROLE_APPLICATION, now overriding with ROLE_SUPPORT or ROLE_INFRASTRUCTURE
if (this.logger.isWarnEnabled()) { if (logger.isWarnEnabled()) {
this.logger.warn("Overriding user-defined bean definition for bean '" + beanName + logger.warn("Overriding user-defined bean definition for bean '" + beanName +
"' with a framework-generated bean definition: replacing [" + "' with a framework-generated bean definition: replacing [" +
oldBeanDefinition + "] with [" + beanDefinition + "]"); oldBeanDefinition + "] with [" + beanDefinition + "]");
} }
} }
else if (!beanDefinition.equals(oldBeanDefinition)) { else if (!beanDefinition.equals(oldBeanDefinition)) {
if (this.logger.isInfoEnabled()) { if (logger.isInfoEnabled()) {
this.logger.info("Overriding bean definition for bean '" + beanName + logger.info("Overriding bean definition for bean '" + beanName +
"' with a different definition: replacing [" + oldBeanDefinition + "' with a different definition: replacing [" + oldBeanDefinition +
"] with [" + beanDefinition + "]"); "] with [" + beanDefinition + "]");
} }
} }
else { else {
if (this.logger.isDebugEnabled()) { if (logger.isDebugEnabled()) {
this.logger.debug("Overriding bean definition for bean '" + beanName + logger.debug("Overriding bean definition for bean '" + beanName +
"' with an equivalent definition: replacing [" + oldBeanDefinition + "' with an equivalent definition: replacing [" + oldBeanDefinition +
"] with [" + beanDefinition + "]"); "] with [" + beanDefinition + "]");
} }
@ -871,8 +871,8 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
BeanDefinition bd = this.beanDefinitionMap.remove(beanName); BeanDefinition bd = this.beanDefinitionMap.remove(beanName);
if (bd == null) { if (bd == null) {
if (this.logger.isTraceEnabled()) { if (logger.isTraceEnabled()) {
this.logger.trace("No bean named '" + beanName + "' found in " + this); logger.trace("No bean named '" + beanName + "' found in " + this);
} }
throw new NoSuchBeanDefinitionException(beanName); throw new NoSuchBeanDefinitionException(beanName);
} }

6
spring-context/src/main/java/org/springframework/remoting/support/SimpleHttpServerFactoryBean.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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -163,8 +163,8 @@ public class SimpleHttpServerFactoryBean implements FactoryBean<HttpServer>, Ini
} }
}); });
} }
if (this.logger.isInfoEnabled()) { if (logger.isInfoEnabled()) {
this.logger.info("Starting HttpServer at address " + address); logger.info("Starting HttpServer at address " + address);
} }
this.server.start(); this.server.start();
} }

2
spring-core/src/main/java/org/springframework/core/SimpleAliasRegistry.java

@ -69,7 +69,7 @@ public class SimpleAliasRegistry implements AliasRegistry {
throw new IllegalStateException("Cannot define alias '" + alias + "' for name '" + throw new IllegalStateException("Cannot define alias '" + alias + "' for name '" +
name + "': It is already registered for name '" + registeredName + "'."); name + "': It is already registered for name '" + registeredName + "'.");
} }
if (this.logger.isInfoEnabled()) { if (logger.isInfoEnabled()) {
logger.info("Overriding alias '" + alias + "' definition for registered name '" + logger.info("Overriding alias '" + alias + "' definition for registered name '" +
registeredName + "' with new target name '" + name + "'"); registeredName + "' with new target name '" + name + "'");
} }

6
spring-core/src/main/java/org/springframework/util/CommonsLogWriter.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2012 the original author or authors. * Copyright 2002-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -45,7 +45,7 @@ public class CommonsLogWriter extends Writer {
public void write(char ch) { public void write(char ch) {
if (ch == '\n' && this.buffer.length() > 0) { if (ch == '\n' && this.buffer.length() > 0) {
this.logger.debug(this.buffer.toString()); logger.debug(this.buffer.toString());
this.buffer.setLength(0); this.buffer.setLength(0);
} }
else { else {
@ -58,7 +58,7 @@ public class CommonsLogWriter extends Writer {
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
char ch = buffer[offset + i]; char ch = buffer[offset + i];
if (ch == '\n' && this.buffer.length() > 0) { if (ch == '\n' && this.buffer.length() > 0) {
this.logger.debug(this.buffer.toString()); logger.debug(this.buffer.toString());
this.buffer.setLength(0); this.buffer.setLength(0);
} }
else { else {

4
spring-jcl/src/main/java/org/apache/commons/logging/LogFactory.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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -603,7 +603,7 @@ public abstract class LogFactory {
} }
private void log(java.util.logging.Level level, Object message, Throwable exception) { private void log(java.util.logging.Level level, Object message, Throwable exception) {
if (logger.isLoggable(level)) { if (this.logger.isLoggable(level)) {
LogRecord rec; LogRecord rec;
if (message instanceof LogRecord) { if (message instanceof LogRecord) {
rec = (LogRecord) message; rec = (LogRecord) message;

4
spring-messaging/src/main/java/org/springframework/messaging/core/GenericMessagingTemplate.java

@ -206,8 +206,8 @@ public class GenericMessagingTemplate extends AbstractDestinationResolvingMessag
Message<?> message = (timeout >= 0 ? Message<?> message = (timeout >= 0 ?
((PollableChannel) channel).receive(timeout) : ((PollableChannel) channel).receive()); ((PollableChannel) channel).receive(timeout) : ((PollableChannel) channel).receive());
if (message == null && this.logger.isTraceEnabled()) { if (message == null && logger.isTraceEnabled()) {
this.logger.trace("Failed to receive message from channel '" + channel + "' within timeout: " + timeout); logger.trace("Failed to receive message from channel '" + channel + "' within timeout: " + timeout);
} }
return message; return message;

8
spring-web/src/main/java/org/springframework/http/server/reactive/AbstractListenerReadPublisher.java

@ -82,7 +82,7 @@ public abstract class AbstractListenerReadPublisher<T> implements Publisher<T> {
* container. * container.
*/ */
public final void onDataAvailable() { public final void onDataAvailable() {
this.logger.trace("I/O event onDataAvailable"); logger.trace("I/O event onDataAvailable");
this.state.get().onDataAvailable(this); this.state.get().onDataAvailable(this);
} }
@ -91,7 +91,7 @@ public abstract class AbstractListenerReadPublisher<T> implements Publisher<T> {
* all data has been read. * all data has been read.
*/ */
public void onAllDataRead() { public void onAllDataRead() {
this.logger.trace("I/O event onAllDataRead"); logger.trace("I/O event onAllDataRead");
this.state.get().onAllDataRead(this); this.state.get().onAllDataRead(this);
} }
@ -99,8 +99,8 @@ public abstract class AbstractListenerReadPublisher<T> implements Publisher<T> {
* Sub-classes can call this to delegate container error notifications. * Sub-classes can call this to delegate container error notifications.
*/ */
public final void onError(Throwable ex) { public final void onError(Throwable ex) {
if (this.logger.isTraceEnabled()) { if (logger.isTraceEnabled()) {
this.logger.trace("I/O event onError: " + ex); logger.trace("I/O event onError: " + ex);
} }
this.state.get().onError(this, ex); this.state.get().onError(this, ex);
} }

2
spring-web/src/main/java/org/springframework/http/server/reactive/AbstractListenerWriteFlushProcessor.java

@ -103,7 +103,7 @@ public abstract class AbstractListenerWriteFlushProcessor<T> implements Processo
* container to cancel the upstream subscription. * container to cancel the upstream subscription.
*/ */
protected void cancel() { protected void cancel() {
this.logger.trace("Received request to cancel"); logger.trace("Received request to cancel");
if (this.subscription != null) { if (this.subscription != null) {
this.subscription.cancel(); this.subscription.cancel();
} }

4
spring-web/src/main/java/org/springframework/http/server/reactive/AbstractListenerWriteProcessor.java

@ -100,7 +100,7 @@ public abstract class AbstractListenerWriteProcessor<T> implements Processor<T,
* container. * container.
*/ */
public final void onWritePossible() { public final void onWritePossible() {
this.logger.trace("Received onWritePossible"); logger.trace("Received onWritePossible");
this.state.get().onWritePossible(this); this.state.get().onWritePossible(this);
} }
@ -109,7 +109,7 @@ public abstract class AbstractListenerWriteProcessor<T> implements Processor<T,
* container to cancel the upstream subscription. * container to cancel the upstream subscription.
*/ */
public void cancel() { public void cancel() {
this.logger.trace("Received request to cancel"); logger.trace("Received request to cancel");
if (this.subscription != null) { if (this.subscription != null) {
this.subscription.cancel(); this.subscription.cancel();
} }

8
spring-web/src/main/java/org/springframework/http/server/reactive/ServletServerHttpResponse.java

@ -313,14 +313,14 @@ class ServletServerHttpResponse extends AbstractListenerServerHttpResponse {
flush(); flush();
} }
boolean ready = ServletServerHttpResponse.this.isWritePossible(); boolean ready = ServletServerHttpResponse.this.isWritePossible();
if (this.logger.isTraceEnabled()) { if (logger.isTraceEnabled()) {
this.logger.trace("write: " + dataBuffer + " ready: " + ready); logger.trace("write: " + dataBuffer + " ready: " + ready);
} }
int remaining = dataBuffer.readableByteCount(); int remaining = dataBuffer.readableByteCount();
if (ready && remaining > 0) { if (ready && remaining > 0) {
int written = writeToOutputStream(dataBuffer); int written = writeToOutputStream(dataBuffer);
if (this.logger.isTraceEnabled()) { if (logger.isTraceEnabled()) {
this.logger.trace("written: " + written + " total: " + remaining); logger.trace("written: " + written + " total: " + remaining);
} }
if (written == remaining) { if (written == remaining) {
if (logger.isTraceEnabled()) { if (logger.isTraceEnabled()) {

6
spring-web/src/main/java/org/springframework/remoting/jaxws/SimpleHttpServerJaxWsServiceExporter.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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -164,8 +164,8 @@ public class SimpleHttpServerJaxWsServiceExporter extends AbstractJaxWsServiceEx
InetSocketAddress address = (this.hostname != null ? InetSocketAddress address = (this.hostname != null ?
new InetSocketAddress(this.hostname, this.port) : new InetSocketAddress(this.port)); new InetSocketAddress(this.hostname, this.port) : new InetSocketAddress(this.port));
HttpServer server = HttpServer.create(address, this.backlog); HttpServer server = HttpServer.create(address, this.backlog);
if (this.logger.isInfoEnabled()) { if (logger.isInfoEnabled()) {
this.logger.info("Starting HttpServer at address " + address); logger.info("Starting HttpServer at address " + address);
} }
server.start(); server.start();
this.server = server; this.server = server;

18
spring-webmvc/src/main/java/org/springframework/web/servlet/FrameworkServlet.java

@ -492,8 +492,8 @@ public abstract class FrameworkServlet extends HttpServletBean implements Applic
@Override @Override
protected final void initServletBean() throws ServletException { protected final void initServletBean() throws ServletException {
getServletContext().log("Initializing Spring FrameworkServlet '" + getServletName() + "'"); getServletContext().log("Initializing Spring FrameworkServlet '" + getServletName() + "'");
if (this.logger.isInfoEnabled()) { if (logger.isInfoEnabled()) {
this.logger.info("FrameworkServlet '" + getServletName() + "': initialization started"); logger.info("FrameworkServlet '" + getServletName() + "': initialization started");
} }
long startTime = System.currentTimeMillis(); long startTime = System.currentTimeMillis();
@ -502,13 +502,13 @@ public abstract class FrameworkServlet extends HttpServletBean implements Applic
initFrameworkServlet(); initFrameworkServlet();
} }
catch (ServletException | RuntimeException ex) { catch (ServletException | RuntimeException ex) {
this.logger.error("Context initialization failed", ex); logger.error("Context initialization failed", ex);
throw ex; throw ex;
} }
if (this.logger.isInfoEnabled()) { if (logger.isInfoEnabled()) {
long elapsedTime = System.currentTimeMillis() - startTime; long elapsedTime = System.currentTimeMillis() - startTime;
this.logger.info("FrameworkServlet '" + getServletName() + "': initialization completed in " + logger.info("FrameworkServlet '" + getServletName() + "': initialization completed in " +
elapsedTime + " ms"); elapsedTime + " ms");
} }
} }
@ -567,8 +567,8 @@ public abstract class FrameworkServlet extends HttpServletBean implements Applic
// Publish the context as a servlet context attribute. // Publish the context as a servlet context attribute.
String attrName = getServletContextAttributeName(); String attrName = getServletContextAttributeName();
getServletContext().setAttribute(attrName, wac); getServletContext().setAttribute(attrName, wac);
if (this.logger.isTraceEnabled()) { if (logger.isTraceEnabled()) {
this.logger.trace("Published WebApplicationContext of servlet '" + getServletName() + logger.trace("Published WebApplicationContext of servlet '" + getServletName() +
"' as ServletContext attribute [" + attrName + "]"); "' as ServletContext attribute [" + attrName + "]");
} }
} }
@ -617,8 +617,8 @@ public abstract class FrameworkServlet extends HttpServletBean implements Applic
*/ */
protected WebApplicationContext createWebApplicationContext(@Nullable ApplicationContext parent) { protected WebApplicationContext createWebApplicationContext(@Nullable ApplicationContext parent) {
Class<?> contextClass = getContextClass(); Class<?> contextClass = getContextClass();
if (this.logger.isTraceEnabled()) { if (logger.isTraceEnabled()) {
this.logger.trace("Servlet '" + getServletName() + logger.trace("Servlet '" + getServletName() +
"' will create custom WebApplicationContext context of class '" + "' will create custom WebApplicationContext context of class '" +
contextClass.getName() + "'" + ", parent context [" + parent + "]"); contextClass.getName() + "'" + ", parent context [" + parent + "]");
} }

Loading…
Cancel
Save