Skip to content

Commit

Permalink
GH-871: Add missing @Nullable
Browse files Browse the repository at this point in the history
Resolves #871

* Add missing `@Nullable`

Relates #871

* Fixup order of imports
  • Loading branch information
knalli authored and artembilan committed Dec 14, 2018
1 parent 963b3b7 commit 427ed3e
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

import java.util.Properties;

import org.springframework.lang.Nullable;


/**
* Specifies a basic set of portable AMQP administrative operations for AMQP > 0.9.
Expand Down Expand Up @@ -50,13 +52,15 @@ public interface AmqpAdmin {
*
* @return The queue.
*/
@Nullable
Queue declareQueue();

/**
* Declare the given queue.
* @param queue the queue to declare.
* @return the name of the queue.
*/
@Nullable
String declareQueue(Queue queue);

/**
Expand Down Expand Up @@ -111,6 +115,7 @@ public interface AmqpAdmin {
* @param queueName the name of the queue.
* @return the properties or null if the queue doesn't exist.
*/
@Nullable
Properties getQueueProperties(String queueName);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.springframework.amqp.AmqpException;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.lang.Nullable;

/**
* Specifies a basic set of AMQP operations.
Expand Down Expand Up @@ -141,6 +142,7 @@ void convertAndSend(String exchange, String routingKey, Object message, MessageP
* @return a message or null if there is none waiting
* @throws AmqpException if there is a problem
*/
@Nullable
Message receive() throws AmqpException;

/**
Expand All @@ -151,6 +153,7 @@ void convertAndSend(String exchange, String routingKey, Object message, MessageP
* @return a message or null if there is none waiting
* @throws AmqpException if there is a problem
*/
@Nullable
Message receive(String queueName) throws AmqpException;

/**
Expand All @@ -164,6 +167,7 @@ void convertAndSend(String exchange, String routingKey, Object message, MessageP
* @throws AmqpException if there is a problem
* @since 1.6
*/
@Nullable
Message receive(long timeoutMillis) throws AmqpException;

/**
Expand All @@ -178,6 +182,7 @@ void convertAndSend(String exchange, String routingKey, Object message, MessageP
* @throws AmqpException if there is a problem
* @since 1.6
*/
@Nullable
Message receive(String queueName, long timeoutMillis) throws AmqpException;

// receive methods with conversion
Expand All @@ -189,6 +194,7 @@ void convertAndSend(String exchange, String routingKey, Object message, MessageP
* @return a message or null if there is none waiting
* @throws AmqpException if there is a problem
*/
@Nullable
Object receiveAndConvert() throws AmqpException;

/**
Expand All @@ -199,6 +205,7 @@ void convertAndSend(String exchange, String routingKey, Object message, MessageP
* @return a message or null if there is none waiting
* @throws AmqpException if there is a problem
*/
@Nullable
Object receiveAndConvert(String queueName) throws AmqpException;

/**
Expand All @@ -213,6 +220,7 @@ void convertAndSend(String exchange, String routingKey, Object message, MessageP
* @throws AmqpException if there is a problem
* @since 1.6
*/
@Nullable
Object receiveAndConvert(long timeoutMillis) throws AmqpException;

/**
Expand All @@ -228,6 +236,7 @@ void convertAndSend(String exchange, String routingKey, Object message, MessageP
* @throws AmqpException if there is a problem
* @since 1.6
*/
@Nullable
Object receiveAndConvert(String queueName, long timeoutMillis) throws AmqpException;

/**
Expand All @@ -241,6 +250,7 @@ void convertAndSend(String exchange, String routingKey, Object message, MessageP
* @throws AmqpException if there is a problem.
* @since 2.0
*/
@Nullable
<T> T receiveAndConvert(ParameterizedTypeReference<T> type) throws AmqpException;

/**
Expand All @@ -255,6 +265,7 @@ void convertAndSend(String exchange, String routingKey, Object message, MessageP
* @throws AmqpException if there is a problem
* @since 2.0
*/
@Nullable
<T> T receiveAndConvert(String queueName, ParameterizedTypeReference<T> type) throws AmqpException;

/**
Expand All @@ -272,6 +283,7 @@ void convertAndSend(String exchange, String routingKey, Object message, MessageP
* @throws AmqpException if there is a problem
* @since 2.0
*/
@Nullable
<T> T receiveAndConvert(long timeoutMillis, ParameterizedTypeReference<T> type) throws AmqpException;

/**
Expand All @@ -290,6 +302,7 @@ void convertAndSend(String exchange, String routingKey, Object message, MessageP
* @throws AmqpException if there is a problem
* @since 2.0
*/
@Nullable
<T> T receiveAndConvert(String queueName, long timeoutMillis, ParameterizedTypeReference<T> type)
throws AmqpException;

Expand Down Expand Up @@ -410,6 +423,7 @@ <R, S> boolean receiveAndReply(String queueName, ReceiveAndReplyCallback<R, S> c
* @return the response if there is one
* @throws AmqpException if there is a problem
*/
@Nullable
Message sendAndReceive(Message message) throws AmqpException;

/**
Expand All @@ -422,6 +436,7 @@ <R, S> boolean receiveAndReply(String queueName, ReceiveAndReplyCallback<R, S> c
* @return the response if there is one
* @throws AmqpException if there is a problem
*/
@Nullable
Message sendAndReceive(String routingKey, Message message) throws AmqpException;

/**
Expand All @@ -436,6 +451,7 @@ <R, S> boolean receiveAndReply(String queueName, ReceiveAndReplyCallback<R, S> c
* @return the response if there is one
* @throws AmqpException if there is a problem
*/
@Nullable
Message sendAndReceive(String exchange, String routingKey, Message message) throws AmqpException;

// send and receive methods with conversion
Expand All @@ -450,6 +466,7 @@ <R, S> boolean receiveAndReply(String queueName, ReceiveAndReplyCallback<R, S> c
* @return the response if there is one
* @throws AmqpException if there is a problem
*/
@Nullable
Object convertSendAndReceive(Object message) throws AmqpException;

/**
Expand All @@ -463,6 +480,7 @@ <R, S> boolean receiveAndReply(String queueName, ReceiveAndReplyCallback<R, S> c
* @return the response if there is one
* @throws AmqpException if there is a problem
*/
@Nullable
Object convertSendAndReceive(String routingKey, Object message) throws AmqpException;

/**
Expand All @@ -477,6 +495,7 @@ <R, S> boolean receiveAndReply(String queueName, ReceiveAndReplyCallback<R, S> c
* @return the response if there is one
* @throws AmqpException if there is a problem
*/
@Nullable
Object convertSendAndReceive(String exchange, String routingKey, Object message) throws AmqpException;

/**
Expand All @@ -490,6 +509,7 @@ <R, S> boolean receiveAndReply(String queueName, ReceiveAndReplyCallback<R, S> c
* @return the response if there is one
* @throws AmqpException if there is a problem
*/
@Nullable
Object convertSendAndReceive(Object message, MessagePostProcessor messagePostProcessor) throws AmqpException;

/**
Expand All @@ -504,6 +524,7 @@ <R, S> boolean receiveAndReply(String queueName, ReceiveAndReplyCallback<R, S> c
* @return the response if there is one
* @throws AmqpException if there is a problem
*/
@Nullable
Object convertSendAndReceive(String routingKey, Object message, MessagePostProcessor messagePostProcessor)
throws AmqpException;

Expand All @@ -520,6 +541,7 @@ Object convertSendAndReceive(String routingKey, Object message, MessagePostProce
* @return the response if there is one
* @throws AmqpException if there is a problem
*/
@Nullable
Object convertSendAndReceive(String exchange, String routingKey, Object message,
MessagePostProcessor messagePostProcessor) throws AmqpException;

Expand All @@ -537,6 +559,7 @@ Object convertSendAndReceive(String exchange, String routingKey, Object message,
* @throws AmqpException if there is a problem.
* @since 2.0
*/
@Nullable
<T> T convertSendAndReceiveAsType(Object message, ParameterizedTypeReference<T> responseType)
throws AmqpException;

Expand All @@ -554,6 +577,7 @@ <T> T convertSendAndReceiveAsType(Object message, ParameterizedTypeReference<T>
* @throws AmqpException if there is a problem
* @since 2.0
*/
@Nullable
<T> T convertSendAndReceiveAsType(String routingKey, Object message,
ParameterizedTypeReference<T> responseType) throws AmqpException;

Expand All @@ -572,6 +596,7 @@ <T> T convertSendAndReceiveAsType(String routingKey, Object message,
* @throws AmqpException if there is a problem
* @since 2.0
*/
@Nullable
<T> T convertSendAndReceiveAsType(String exchange, String routingKey, Object message,
ParameterizedTypeReference<T> responseType) throws AmqpException;

Expand All @@ -589,6 +614,7 @@ <T> T convertSendAndReceiveAsType(String exchange, String routingKey, Object mes
* @throws AmqpException if there is a problem
* @since 2.0
*/
@Nullable
<T> T convertSendAndReceiveAsType(Object message, MessagePostProcessor messagePostProcessor,
ParameterizedTypeReference<T> responseType) throws AmqpException;

Expand All @@ -607,6 +633,7 @@ <T> T convertSendAndReceiveAsType(Object message, MessagePostProcessor messagePo
* @throws AmqpException if there is a problem
* @since 2.0
*/
@Nullable
<T> T convertSendAndReceiveAsType(String routingKey, Object message,
MessagePostProcessor messagePostProcessor, ParameterizedTypeReference<T> responseType)
throws AmqpException;
Expand All @@ -627,6 +654,7 @@ <T> T convertSendAndReceiveAsType(String routingKey, Object message,
* @throws AmqpException if there is a problem
* @since 2.0
*/
@Nullable
<T> T convertSendAndReceiveAsType(String exchange, String routingKey, Object message,
MessagePostProcessor messagePostProcessor, ParameterizedTypeReference<T> responseType)
throws AmqpException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package org.springframework.amqp.rabbit.core;

import org.springframework.lang.Nullable;

import com.rabbitmq.client.Channel;

/**
Expand All @@ -36,6 +38,7 @@ public interface ChannelCallback<T> {
* @return The result.
* @throws Exception Not sure what else Rabbit Throws
*/
@Nullable
T doInRabbit(Channel channel) throws Exception; // NOSONAR user code might throw anything; cannot change

}
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ public boolean deleteExchange(final String exchangeName) {
@Override
@ManagedOperation(description =
"Declare a queue on the broker (this operation is not available remotely)")
@Nullable
public String declareQueue(final Queue queue) {
try {
return this.rabbitTemplate.execute(channel -> {
Expand Down Expand Up @@ -388,6 +389,7 @@ public void removeBinding(final Binding binding) {
*/
@Override
@ManagedOperation(description = "Get queue name, message count and consumer count")
@Nullable
public Properties getQueueProperties(final String queueName) {
Assert.hasText(queueName, "'queueName' cannot be null or empty");
return this.rabbitTemplate.execute(channel -> {
Expand Down Expand Up @@ -434,7 +436,7 @@ public Properties getQueueProperties(final String queueName) {
* @param retryTemplate the retry template.
* @since 1.7.8
*/
public void setRetryTemplate(RetryTemplate retryTemplate) {
public void setRetryTemplate(@Nullable RetryTemplate retryTemplate) {
this.retryTemplate = retryTemplate;
if (retryTemplate == null) {
this.retryDisabled = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1013,11 +1013,13 @@ public void convertAndSend(String exchange, String routingKey, final Object mess
}

@Override
@Nullable
public Message receive() throws AmqpException {
return this.receive(getRequiredQueue());
}

@Override
@Nullable
public Message receive(String queueName) {
if (this.receiveTimeout == 0) {
return doReceiveNoWait(queueName);
Expand All @@ -1033,6 +1035,7 @@ public Message receive(String queueName) {
* @return The message, or null if none immediately available.
* @since 1.5
*/
@Nullable
protected Message doReceiveNoWait(final String queueName) {
Message message = execute(channel -> {
GetResponse response = channel.basicGet(queueName, !isChannelTransacted());
Expand Down Expand Up @@ -1934,11 +1937,13 @@ public Boolean isMandatoryFor(final Message message) {
}

@Override
@Nullable
public <T> T execute(ChannelCallback<T> action) {
return execute(action, getConnectionFactory());
}

@SuppressWarnings(UNCHECKED)
@Nullable
private <T> T execute(final ChannelCallback<T> action, final ConnectionFactory connectionFactory) {
if (this.retryTemplate != null) {
try {
Expand All @@ -1958,7 +1963,7 @@ private <T> T execute(final ChannelCallback<T> action, final ConnectionFactory c
}
}


@Nullable
private <T> T doExecute(ChannelCallback<T> action, ConnectionFactory connectionFactory) { // NOSONAR complexity
Assert.notNull(action, "Callback object must not be null");
Channel channel = null;
Expand Down

0 comments on commit 427ed3e

Please sign in to comment.