Fix Sonar @NonNullApi violations

This commit is contained in:
Gary Russell
2018-10-25 16:57:22 -04:00
parent 9e91234545
commit 2f2f6a8edb
13 changed files with 40 additions and 15 deletions

View File

@@ -54,6 +54,7 @@ import org.springframework.amqp.support.ConditionalExceptionLogger;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.jmx.export.annotation.ManagedAttribute;
import org.springframework.jmx.export.annotation.ManagedResource;
import org.springframework.lang.Nullable;
import org.springframework.scheduling.concurrent.CustomizableThreadFactory;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
@@ -197,7 +198,7 @@ public class CachingConnectionFactory extends AbstractConnectionFactory
* Create a new CachingConnectionFactory given a host name.
* @param hostname the host name to connect to
*/
public CachingConnectionFactory(String hostname) {
public CachingConnectionFactory(@Nullable String hostname) {
this(hostname, com.rabbitmq.client.ConnectionFactory.DEFAULT_AMQP_PORT);
}
@@ -216,7 +217,7 @@ public class CachingConnectionFactory extends AbstractConnectionFactory
* @param hostname the host name to connect to
* @param port the port number
*/
public CachingConnectionFactory(String hostname, int port) {
public CachingConnectionFactory(@Nullable String hostname, int port) {
super(newRabbitConnectionFactory());
if (!StringUtils.hasText(hostname)) {
hostname = getDefaultHostName();
@@ -596,6 +597,7 @@ public class CachingConnectionFactory extends AbstractConnectionFactory
transactional));
}
@Nullable
private Channel createBareChannel(ChannelCachingConnectionProxy connection, boolean transactional) {
if (this.cacheMode == CacheMode.CHANNEL) {
if (!this.connection.isOpen()) {
@@ -625,6 +627,7 @@ public class CachingConnectionFactory extends AbstractConnectionFactory
return null;
}
@Nullable
private Channel doCreateBareChannel(ChannelCachingConnectionProxy connection, boolean transactional) {
Channel channel = connection.createBareChannel(transactional);
if (this.publisherConfirms || this.simplePublisherConfirms) {
@@ -646,6 +649,7 @@ public class CachingConnectionFactory extends AbstractConnectionFactory
return channel;
}
@Nullable
@Override
public final Connection createConnection() throws AmqpException {
if (this.stopped) {

View File

@@ -31,6 +31,7 @@ import org.springframework.lang.Nullable;
*/
public interface ConnectionFactory {
@Nullable
Connection createConnection() throws AmqpException;
String getHost();

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.
@@ -19,6 +19,8 @@ package org.springframework.amqp.rabbit.connection;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.lang.Nullable;
import com.rabbitmq.client.Channel;
/**
@@ -78,6 +80,7 @@ public final class ConsumerChannelRegistry {
*
* @return The channel.
*/
@Nullable
public static Channel getConsumerChannel() {
ChannelHolder channelHolder = consumerChannel.get();
Channel channel = null;
@@ -94,6 +97,7 @@ public final class ConsumerChannelRegistry {
* @param connectionFactory The connection factory.
* @return The channel.
*/
@Nullable
public static Channel getConsumerChannel(ConnectionFactory connectionFactory) {
ChannelHolder channelHolder = consumerChannel.get();
Channel channel = null;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015-2016 the original author or authors.
* Copyright 2015-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.
@@ -28,6 +28,7 @@ import org.apache.commons.logging.LogFactory;
import org.springframework.amqp.AmqpException;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.core.io.Resource;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import com.rabbitmq.http.client.Client;
@@ -270,6 +271,7 @@ public class LocalizedQueueConnectionFactory implements ConnectionFactory, Routi
}
}
@Nullable
private ConnectionFactory determineConnectionFactory(String queue) {
for (int i = 0; i < this.adminUris.length; i++) {
String adminUri = this.adminUris[i];

View File

@@ -44,6 +44,7 @@ import org.springframework.amqp.core.MessageProperties;
import org.springframework.amqp.rabbit.connection.CorrelationData.Confirm;
import org.springframework.amqp.rabbit.support.DefaultMessagePropertiesConverter;
import org.springframework.amqp.rabbit.support.MessagePropertiesConverter;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
@@ -115,7 +116,7 @@ public class PublisherCallbackChannelImpl
this(delegate, null);
}
public PublisherCallbackChannelImpl(Channel delegate, ExecutorService executor) {
public PublisherCallbackChannelImpl(Channel delegate, @Nullable ExecutorService executor) {
delegate.addShutdownListener(this);
this.delegate = delegate;
this.executor = executor != null ? executor : DEFAULT_EXECUTOR;

View File

@@ -29,6 +29,7 @@ import org.springframework.amqp.AmqpException;
import org.springframework.amqp.AmqpIOException;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.rabbit.transaction.RabbitTransactionManager;
import org.springframework.lang.Nullable;
import org.springframework.transaction.support.ResourceHolderSupport;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
@@ -122,7 +123,7 @@ public class RabbitResourceHolder extends ResourceHolderSupport {
addChannel(channel, null);
}
public final void addChannel(Channel channel, Connection connection) {
public final void addChannel(Channel channel, @Nullable Connection connection) {
Assert.isTrue(!this.frozen, "Cannot add Channel because RabbitResourceHolder is frozen");
Assert.notNull(channel, "Channel must not be null");
if (!this.channels.contains(channel)) {
@@ -142,6 +143,7 @@ public class RabbitResourceHolder extends ResourceHolderSupport {
return this.channels.contains(channel);
}
@Nullable
public Connection getConnection() {
return (!this.connections.isEmpty() ? this.connections.get(0) : null);
}
@@ -150,6 +152,7 @@ public class RabbitResourceHolder extends ResourceHolderSupport {
return CollectionUtils.findValueOfType(this.connections, connectionType);
}
@Nullable
public Channel getChannel() {
return (!this.channels.isEmpty() ? this.channels.get(0) : null);
}

View File

@@ -24,6 +24,7 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.core.NamedThreadLocal;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
@@ -90,6 +91,7 @@ public final class SimpleResourceHolder {
* @param actualKey the key.
* @return the resource object.
*/
@Nullable
private static Object doGet(Object actualKey) {
Map<Object, Object> map = resources.get();
if (map == null) {
@@ -137,6 +139,7 @@ public final class SimpleResourceHolder {
* @param key the key to unbind (usually the resource factory)
* @return the previously bound value, or <code>null</code> if none bound
*/
@Nullable
public static Object unbindIfPossible(Object key) {
Map<Object, Object> map = resources.get();
if (map == null) {

View File

@@ -205,7 +205,7 @@ public class BrokerEventListener implements MessageListener, ApplicationEventPub
}
@Override
public void onCreate(Connection connection) {
public void onCreate(@Nullable Connection connection) {
this.bindingsFailedException = null;
TopicExchange exchange = new TopicExchange("amq.rabbitmq.event");
try {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016 the original author or authors.
* Copyright 2016-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.amqp.rabbit.core;
import org.springframework.amqp.core.Declarable;
import org.springframework.lang.Nullable;
/**
* Application event published when a declaration exception occurs.
@@ -33,7 +34,7 @@ public class DeclarationExceptionEvent extends RabbitAdminEvent {
private final Throwable throwable;
public DeclarationExceptionEvent(Object source, Declarable declarable, Throwable t) {
public DeclarationExceptionEvent(Object source, @Nullable Declarable declarable, Throwable t) {
super(source);
this.declarable = declarable;
this.throwable = t;

View File

@@ -53,6 +53,7 @@ import org.springframework.core.task.SimpleAsyncTaskExecutor;
import org.springframework.core.task.TaskExecutor;
import org.springframework.jmx.export.annotation.ManagedOperation;
import org.springframework.jmx.export.annotation.ManagedResource;
import org.springframework.lang.Nullable;
import org.springframework.retry.backoff.ExponentialBackOffPolicy;
import org.springframework.retry.policy.SimpleRetryPolicy;
import org.springframework.retry.support.RetryTemplate;
@@ -744,8 +745,9 @@ public class RabbitAdmin implements AmqpAdmin, ApplicationContextAware, Applicat
}
}
private <T extends Throwable> void logOrRethrowDeclarationException(Declarable element, String elementType, T t)
throws T {
private <T extends Throwable> void logOrRethrowDeclarationException(@Nullable Declarable element,
String elementType, T t) throws T {
DeclarationExceptionEvent event = new DeclarationExceptionEvent(this, element, t);
this.lastDeclarationExceptionEvent = event;
if (this.applicationEventPublisher != null) {

View File

@@ -870,7 +870,7 @@ public class RabbitTemplate extends RabbitAccessor implements BeanFactoryAware,
@Override
public void send(final String exchange, final String routingKey,
final Message message, final CorrelationData correlationData)
final Message message, @Nullable final CorrelationData correlationData)
throws AmqpException {
execute(channel -> {
doSend(channel, exchange, routingKey, message,

View File

@@ -17,6 +17,7 @@
package org.springframework.amqp.rabbit.listener;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.lang.Nullable;
/**
* Model for a Rabbit listener endpoint. Can be used against a
@@ -87,6 +88,7 @@ public interface RabbitListenerEndpoint {
* @return the converter.
* @since 2.0.8
*/
@Nullable
default MessageConverter getMessageConverter() {
return null;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2016 the original author or authors.
* Copyright 2014-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.
@@ -22,6 +22,7 @@ import java.util.List;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.lang.Nullable;
import org.springframework.messaging.handler.annotation.support.DefaultMessageHandlerMethodFactory;
import org.springframework.messaging.handler.annotation.support.MessageHandlerMethodFactory;
import org.springframework.util.Assert;
@@ -166,7 +167,8 @@ public class RabbitListenerEndpointRegistrar implements BeanFactoryAware, Initia
* @param endpoint the {@link RabbitListenerEndpoint} instance to register.
* @param factory the {@link RabbitListenerContainerFactory} to use.
*/
public void registerEndpoint(RabbitListenerEndpoint endpoint, RabbitListenerContainerFactory<?> factory) {
public void registerEndpoint(RabbitListenerEndpoint endpoint,
@Nullable RabbitListenerContainerFactory<?> factory) {
Assert.notNull(endpoint, "Endpoint must be set");
Assert.hasText(endpoint.getId(), "Endpoint id must be set");
// Factory may be null, we defer the resolution right before actually creating the container
@@ -201,7 +203,7 @@ public class RabbitListenerEndpointRegistrar implements BeanFactoryAware, Initia
private final RabbitListenerContainerFactory<?> containerFactory;
AmqpListenerEndpointDescriptor(RabbitListenerEndpoint endpoint,
RabbitListenerContainerFactory<?> containerFactory) {
@Nullable RabbitListenerContainerFactory<?> containerFactory) {
this.endpoint = endpoint;
this.containerFactory = containerFactory;
}