RequireThis rule and fixThis Gradle task

* `gradlew clean check -x test --parallel --continue` - to collect reports
* `gradlew fixThis --parallel` - to fix all possible vulnerabilities. With `-Dfile.encoding=UTF-8` on Windows

Since the `RequireThisCheck` doesn't see parents for anonymous classes (e.g. `Runnable` callback), its report doesn't contains the outer class name with `this.`,
therefore we still have to fix those cases manually.
Thanks to the wrong `replacer` just with `this.` we have uncompilable code enough easy to find problems.
Not so easy to fix for good readability though...

* Upgrade to Grade 2.12
* Upgrade to SonarQube native plugin

The fix contains at about 300 files. So, will be done on merge.

Fix `fixThis.gradle` according PR comments

Apply `fixThis` and also `fixModifiers` for test classes.
 Fix some `this.` inner issues manually.
 Make code polishing for long lines after `fixThis`

Fix conflicts and vulnerabilities after the rebase
This commit is contained in:
Artem Bilan
2016-03-17 17:02:15 -04:00
parent e189307ab6
commit 2b0598291c
348 changed files with 1828 additions and 1781 deletions

View File

@@ -69,7 +69,7 @@ public class DefaultMBeanObjectConverter implements MBeanObjectConverter {
for (MBeanAttributeInfo attrInfo : attributeInfos) {
// we don't need to repeat name of this as an attribute
if ("ObjectName".equals(attrInfo.getName()) || !filter.accept(objName, attrInfo.getName())) {
if ("ObjectName".equals(attrInfo.getName()) || !this.filter.accept(objName, attrInfo.getName())) {
continue;
}

View File

@@ -70,10 +70,10 @@ public class MBeanTreePollingMessageSource extends AbstractMessageSource<Object>
try {
Map<String, Object> beans = new HashMap<String, Object>();
Set<ObjectInstance> results = server.queryMBeans(queryName, queryExpression);
Set<ObjectInstance> results = this.server.queryMBeans(this.queryName, this.queryExpression);
for (ObjectInstance instance : results) {
Object result = converter.convert(server, instance);
Object result = this.converter.convert(this.server, instance);
beans.put(instance.getObjectName().getCanonicalName(), result);
}

View File

@@ -38,7 +38,7 @@ public class NamedFieldsMBeanAttributeFilter implements MBeanAttributeFilter {
@Override
public boolean accept(ObjectName objectName, String attributeName) {
for (String namedField : namedFields) {
for (String namedField : this.namedFields) {
if (namedField.equals(attributeName)) {
return true;
}

View File

@@ -38,7 +38,7 @@ public class NotNamedFieldsMBeanAttributeFilter implements MBeanAttributeFilter
@Override
public boolean accept(ObjectName objectName, String attributeName) {
for (String namedField : namedFields) {
for (String namedField : this.namedFields) {
if (namedField.equals(attributeName)) {
return false;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2016 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.
@@ -119,8 +119,8 @@ public class NotificationListeningMessageProducer extends MessageProducerSupport
*/
@Override
public void handleNotification(Notification notification, Object handback) {
if (logger.isInfoEnabled()) {
logger.info("received notification: " + notification + ", and handback: " + handback);
if (this.logger.isInfoEnabled()) {
this.logger.info("received notification: " + notification + ", and handback: " + handback);
}
AbstractIntegrationMessageBuilder<?> builder = this.getMessageBuilderFactory().withPayload(notification);
if (handback != null) {
@@ -155,13 +155,13 @@ public class NotificationListeningMessageProducer extends MessageProducerSupport
if (!this.listenerRegisteredOnStartup.get()) {
return;
}
logger.debug("Registering to receive notifications");
this.logger.debug("Registering to receive notifications");
try {
Assert.notNull(this.server, "MBeanServer is required.");
Assert.notNull(this.objectNames, "An ObjectName is required.");
Collection<ObjectName> objectNames = this.retrieveMBeanNames();
if (objectNames.size() < 1) {
logger.error("No MBeans found matching ObjectName pattern(s): " +
this.logger.error("No MBeans found matching ObjectName pattern(s): " +
Arrays.asList(this.objectNames));
}
for (ObjectName objectName : objectNames) {
@@ -181,7 +181,7 @@ public class NotificationListeningMessageProducer extends MessageProducerSupport
*/
@Override
protected void doStop() {
logger.debug("Unregistering notifications");
this.logger.debug("Unregistering notifications");
if (this.server != null && this.objectNames != null) {
Collection<ObjectName> objectNames = this.retrieveMBeanNames();
for (ObjectName objectName : objectNames) {
@@ -189,13 +189,13 @@ public class NotificationListeningMessageProducer extends MessageProducerSupport
this.server.removeNotificationListener(objectName, this, this.filter, this.handback);
}
catch (InstanceNotFoundException e) {
logger.error("Failed to find MBean instance.", e);
this.logger.error("Failed to find MBean instance.", e);
}
catch (ListenerNotFoundException e) {
logger.error("Failed to find NotificationListener.", e);
this.logger.error("Failed to find NotificationListener.", e);
}
catch (IOException e) {
logger.error("IOException on MBeanServerConnection.", e);
this.logger.error("IOException on MBeanServerConnection.", e);
}
}
}
@@ -211,12 +211,12 @@ public class NotificationListeningMessageProducer extends MessageProducerSupport
catch (IOException e) {
throw new IllegalStateException("IOException on MBeanServerConnection.", e);
}
if (mBeanInfos.size() == 0 && logger.isDebugEnabled()) {
logger.debug("No MBeans found matching pattern:" + pattern);
if (mBeanInfos.size() == 0 && this.logger.isDebugEnabled()) {
this.logger.debug("No MBeans found matching pattern:" + pattern);
}
for (ObjectInstance instance : mBeanInfos) {
if (logger.isDebugEnabled()) {
logger.debug("Found MBean:" + instance.getObjectName().toString());
if (this.logger.isDebugEnabled()) {
this.logger.debug("Found MBean:" + instance.getObjectName().toString());
}
objectNames.add(instance.getObjectName());
}

View File

@@ -162,9 +162,9 @@ public class IntegrationMBeanExporter extends MBeanExporter implements Applicati
private final Properties objectNameStaticProperties = new Properties();
private final MetadataMBeanInfoAssembler assembler = new IntegrationMetadataMBeanInfoAssembler(attributeSource);
private final MetadataMBeanInfoAssembler assembler = new IntegrationMetadataMBeanInfoAssembler(this.attributeSource);
private final MetadataNamingStrategy defaultNamingStrategy = new IntegrationMetadataNamingStrategy(attributeSource);
private final MetadataNamingStrategy defaultNamingStrategy = new IntegrationMetadataNamingStrategy(this.attributeSource);
private String[] componentNamePatterns = { "*" };
@@ -177,8 +177,8 @@ public class IntegrationMBeanExporter extends MBeanExporter implements Applicati
super();
// Shouldn't be necessary, but to be on the safe side...
setAutodetect(false);
setNamingStrategy(defaultNamingStrategy);
setAssembler(assembler);
setNamingStrategy(this.defaultNamingStrategy);
setAssembler(this.assembler);
}
/**
@@ -383,13 +383,13 @@ public class IntegrationMBeanExporter extends MBeanExporter implements Applicati
@Override
public void destroy() {
super.destroy();
channelsByName.clear();
handlersByName.clear();
sourcesByName.clear();
for (MessageChannelMetrics monitor : channels) {
this.channelsByName.clear();
this.handlersByName.clear();
this.sourcesByName.clear();
for (MessageChannelMetrics monitor : this.channels) {
logger.info("Summary on shutdown: " + monitor);
}
for (MessageHandlerMetrics monitor : handlers) {
for (MessageHandlerMetrics monitor : this.handlers) {
logger.info("Summary on shutdown: " + monitor);
}
}
@@ -427,7 +427,7 @@ public class IntegrationMBeanExporter extends MBeanExporter implements Applicati
stopMessageSources();
stopInboundMessageProducers();
// Wait any remaining time for messages to quiesce
long timeLeft = shutdownDeadline - System.currentTimeMillis();
long timeLeft = this.shutdownDeadline - System.currentTimeMillis();
if (timeLeft > 0) {
try {
Thread.sleep(timeLeft);
@@ -440,7 +440,7 @@ public class IntegrationMBeanExporter extends MBeanExporter implements Applicati
orderlyShutdownCapableComponentsAfter();
}
finally {
shuttingDown.set(false);
this.shuttingDown.set(false);
}
}
@@ -526,17 +526,17 @@ public class IntegrationMBeanExporter extends MBeanExporter implements Applicati
@ManagedMetric(metricType = MetricType.COUNTER, displayName = "MessageChannel Channel Count")
public int getChannelCount() {
return channelsByName.size();
return this.channelsByName.size();
}
@ManagedMetric(metricType = MetricType.COUNTER, displayName = "MessageHandler Handler Count")
public int getHandlerCount() {
return handlersByName.size();
return this.handlersByName.size();
}
@ManagedAttribute
public String[] getHandlerNames() {
return handlersByName.keySet().toArray(new String[handlersByName.size()]);
return this.handlersByName.keySet().toArray(new String[this.handlersByName.size()]);
}
@ManagedMetric(metricType = MetricType.GAUGE, displayName = "Active Handler Count")
@@ -547,7 +547,7 @@ public class IntegrationMBeanExporter extends MBeanExporter implements Applicati
@ManagedMetric(metricType = MetricType.GAUGE, displayName = "Active Handler Count")
public long getActiveHandlerCountLong() {
int count = 0;
for (MessageHandlerMetrics monitor : handlers) {
for (MessageHandlerMetrics monitor : this.handlers) {
count += monitor.getActiveCountLong();
}
return count;
@@ -556,7 +556,7 @@ public class IntegrationMBeanExporter extends MBeanExporter implements Applicati
@ManagedMetric(metricType = MetricType.GAUGE, displayName = "Queued Message Count")
public int getQueuedMessageCount() {
int count = 0;
for (MessageChannelMetrics monitor : channels) {
for (MessageChannelMetrics monitor : this.channels) {
if (monitor instanceof QueueChannel) {
count += ((QueueChannel) monitor).getQueueSize();
}
@@ -566,28 +566,28 @@ public class IntegrationMBeanExporter extends MBeanExporter implements Applicati
@ManagedAttribute
public String[] getChannelNames() {
return channelsByName.keySet().toArray(new String[channelsByName.size()]);
return this.channelsByName.keySet().toArray(new String[this.channelsByName.size()]);
}
public MessageHandlerMetrics getHandlerMetrics(String name) {
if (handlersByName.containsKey(name)) {
return handlersByName.get(name);
if (this.handlersByName.containsKey(name)) {
return this.handlersByName.get(name);
}
logger.debug("No handler found for (" + name + ")");
return null;
}
public Statistics getHandlerDuration(String name) {
if (handlersByName.containsKey(name)) {
return handlersByName.get(name).getDuration();
if (this.handlersByName.containsKey(name)) {
return this.handlersByName.get(name).getDuration();
}
logger.debug("No handler found for (" + name + ")");
return null;
}
public MessageSourceMetrics getSourceMetrics(String name) {
if (sourcesByName.containsKey(name)) {
return sourcesByName.get(name);
if (this.sourcesByName.containsKey(name)) {
return this.sourcesByName.get(name);
}
logger.debug("No source found for (" + name + ")");
return null;
@@ -598,16 +598,16 @@ public class IntegrationMBeanExporter extends MBeanExporter implements Applicati
}
public long getSourceMessageCountLong(String name) {
if (sourcesByName.containsKey(name)) {
return sourcesByName.get(name).getMessageCountLong();
if (this.sourcesByName.containsKey(name)) {
return this.sourcesByName.get(name).getMessageCountLong();
}
logger.debug("No source found for (" + name + ")");
return -1;
}
public MessageChannelMetrics getChannelMetrics(String name) {
if (channelsByName.containsKey(name)) {
return channelsByName.get(name);
if (this.channelsByName.containsKey(name)) {
return this.channelsByName.get(name);
}
logger.debug("No channel found for (" + name + ")");
return null;
@@ -618,8 +618,8 @@ public class IntegrationMBeanExporter extends MBeanExporter implements Applicati
}
public long getChannelSendCountLong(String name) {
if (channelsByName.containsKey(name)) {
return channelsByName.get(name).getSendCountLong();
if (this.channelsByName.containsKey(name)) {
return this.channelsByName.get(name).getSendCountLong();
}
logger.debug("No channel found for (" + name + ")");
return -1;
@@ -630,8 +630,8 @@ public class IntegrationMBeanExporter extends MBeanExporter implements Applicati
}
public long getChannelSendErrorCountLong(String name) {
if (channelsByName.containsKey(name)) {
return channelsByName.get(name).getSendErrorCountLong();
if (this.channelsByName.containsKey(name)) {
return this.channelsByName.get(name).getSendErrorCountLong();
}
logger.debug("No channel found for (" + name + ")");
return -1;
@@ -642,9 +642,9 @@ public class IntegrationMBeanExporter extends MBeanExporter implements Applicati
}
public long getChannelReceiveCountLong(String name) {
if (channelsByName.containsKey(name)) {
if (channelsByName.get(name) instanceof PollableChannelManagement) {
return ((PollableChannelManagement) channelsByName.get(name)).getReceiveCountLong();
if (this.channelsByName.containsKey(name)) {
if (this.channelsByName.get(name) instanceof PollableChannelManagement) {
return ((PollableChannelManagement) this.channelsByName.get(name)).getReceiveCountLong();
}
}
logger.debug("No channel found for (" + name + ")");
@@ -653,34 +653,34 @@ public class IntegrationMBeanExporter extends MBeanExporter implements Applicati
@ManagedOperation
public Statistics getChannelSendRate(String name) {
if (channelsByName.containsKey(name)) {
return channelsByName.get(name).getSendRate();
if (this.channelsByName.containsKey(name)) {
return this.channelsByName.get(name).getSendRate();
}
logger.debug("No channel found for (" + name + ")");
return null;
}
public Statistics getChannelErrorRate(String name) {
if (channelsByName.containsKey(name)) {
return channelsByName.get(name).getErrorRate();
if (this.channelsByName.containsKey(name)) {
return this.channelsByName.get(name).getErrorRate();
}
logger.debug("No channel found for (" + name + ")");
return null;
}
private void registerChannels() {
for (MessageChannelMetrics monitor : channels) {
for (MessageChannelMetrics monitor : this.channels) {
String name = ((NamedComponent) monitor).getComponentName();
this.allChannelsByName.put(name, monitor);
if (!matches(this.componentNamePatterns, name)) {
continue;
}
// Only register once...
if (!channelsByName.containsKey(name)) {
if (!this.channelsByName.containsKey(name)) {
String beanKey = getChannelBeanKey(name);
logger.info("Registering MessageChannel " + name);
if (name != null) {
channelsByName.put(name, monitor);
this.channelsByName.put(name, monitor);
}
registerBeanNameOrInstance(monitor, beanKey);
}
@@ -688,7 +688,7 @@ public class IntegrationMBeanExporter extends MBeanExporter implements Applicati
}
private void registerHandlers() {
for (MessageHandlerMetrics handler : handlers) {
for (MessageHandlerMetrics handler : this.handlers) {
MessageHandlerMetrics monitor = enhanceHandlerMonitor(handler);
String name = monitor.getManagedName();
this.allHandlersByName.put(name, monitor);
@@ -696,10 +696,10 @@ public class IntegrationMBeanExporter extends MBeanExporter implements Applicati
continue;
}
// Only register once...
if (!handlersByName.containsKey(name)) {
if (!this.handlersByName.containsKey(name)) {
String beanKey = getHandlerBeanKey(monitor);
if (name != null) {
handlersByName.put(name, monitor);
this.handlersByName.put(name, monitor);
}
registerBeanNameOrInstance(monitor, beanKey);
}
@@ -707,7 +707,7 @@ public class IntegrationMBeanExporter extends MBeanExporter implements Applicati
}
private void registerSources() {
for (MessageSourceMetrics source : sources) {
for (MessageSourceMetrics source : this.sources) {
MessageSourceMetrics monitor = enhanceSourceMonitor(source);
String name = monitor.getManagedName();
this.allSourcesByName.put(name, monitor);
@@ -715,10 +715,10 @@ public class IntegrationMBeanExporter extends MBeanExporter implements Applicati
continue;
}
// Only register once...
if (!sourcesByName.containsKey(name)) {
if (!this.sourcesByName.containsKey(name)) {
String beanKey = getSourceBeanKey(monitor);
if (name != null) {
sourcesByName.put(name, monitor);
this.sourcesByName.put(name, monitor);
}
registerBeanNameOrInstance(monitor, beanKey);
}
@@ -729,7 +729,7 @@ public class IntegrationMBeanExporter extends MBeanExporter implements Applicati
String[] names = this.applicationContext.getBeanNamesForType(AbstractEndpoint.class);
Set<String> endpointNames = new HashSet<String>();
for (String name : names) {
if (!beansByEndpointName.values().contains(name)) {
if (!this.beansByEndpointName.values().contains(name)) {
AbstractEndpoint endpoint = this.applicationContext.getBean(name, AbstractEndpoint.class);
String beanKey;
name = endpoint.getComponentName();
@@ -822,28 +822,28 @@ public class IntegrationMBeanExporter extends MBeanExporter implements Applicati
if (name.startsWith("org.springframework.integration")) {
name = name + ",source=anonymous";
}
return String.format(domain + ":type=MessageChannel,name=%s" + getStaticNames(), name);
return String.format(this.domain + ":type=MessageChannel,name=%s" + getStaticNames(), name);
}
private String getHandlerBeanKey(MessageHandlerMetrics handler) {
// This ordering of keys seems to work with default settings of JConsole
return String.format(domain + ":type=MessageHandler,name=%s,bean=%s" + getStaticNames(),
return String.format(this.domain + ":type=MessageHandler,name=%s,bean=%s" + getStaticNames(),
handler.getManagedName(), handler.getManagedType());
}
private String getSourceBeanKey(MessageSourceMetrics source) {
// This ordering of keys seems to work with default settings of JConsole
return String.format(domain + ":type=MessageSource,name=%s,bean=%s" + getStaticNames(),
return String.format(this.domain + ":type=MessageSource,name=%s,bean=%s" + getStaticNames(),
source.getManagedName(), source.getManagedType());
}
private String getEndpointBeanKey(AbstractEndpoint endpoint, String name, String source) {
// This ordering of keys seems to work with default settings of JConsole
return String.format(domain + ":type=ManagedEndpoint,name=%s,bean=%s" + getStaticNames(), name, source);
return String.format(this.domain + ":type=ManagedEndpoint,name=%s,bean=%s" + getStaticNames(), name, source);
}
private String getStaticNames() {
if (objectNameStaticProperties.isEmpty()) {
if (this.objectNameStaticProperties.isEmpty()) {
return "";
}
StringBuilder builder = new StringBuilder();
@@ -904,10 +904,10 @@ public class IntegrationMBeanExporter extends MBeanExporter implements Applicati
}
Object field = getField(target, "inputChannel");
if (field != null) {
if (!anonymousHandlerCounters.containsKey(field)) {
anonymousHandlerCounters.put(field, new AtomicLong());
if (!this.anonymousHandlerCounters.containsKey(field)) {
this.anonymousHandlerCounters.put(field, new AtomicLong());
}
AtomicLong count = anonymousHandlerCounters.get(field);
AtomicLong count = this.anonymousHandlerCounters.get(field);
long total = count.incrementAndGet();
String suffix = "";
/*
@@ -952,7 +952,7 @@ public class IntegrationMBeanExporter extends MBeanExporter implements Applicati
}
if (endpointName != null) {
beansByEndpointName.put(name, endpointName);
this.beansByEndpointName.put(name, endpointName);
}
monitor.setManagedType(source);
@@ -1030,10 +1030,10 @@ public class IntegrationMBeanExporter extends MBeanExporter implements Applicati
}
if (outputChannel != null) {
if (!anonymousSourceCounters.containsKey(outputChannel)) {
anonymousSourceCounters.put(outputChannel, new AtomicLong());
if (!this.anonymousSourceCounters.containsKey(outputChannel)) {
this.anonymousSourceCounters.put(outputChannel, new AtomicLong());
}
AtomicLong count = anonymousSourceCounters.get(outputChannel);
AtomicLong count = this.anonymousSourceCounters.get(outputChannel);
long total = count.incrementAndGet();
String suffix = "";
/*
@@ -1063,7 +1063,7 @@ public class IntegrationMBeanExporter extends MBeanExporter implements Applicati
}
if (endpointName != null) {
beansByEndpointName.put(name, endpointName);
this.beansByEndpointName.put(name, endpointName);
}
monitor.setManagedType(source);

View File

@@ -41,19 +41,19 @@ public class ManagedEndpoint implements Lifecycle {
@Override
@ManagedAttribute
public final boolean isRunning() {
return delegate.isRunning();
return this.delegate.isRunning();
}
@Override
@ManagedOperation
public final void start() {
delegate.start();
this.delegate.start();
}
@Override
@ManagedOperation
public final void stop() {
delegate.stop();
this.delegate.stop();
}
}