Skip to content

Data in handle method is @Nullable #1837

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 22, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

import org.springframework.core.log.LogAccessor;

import org.springframework.lang.Nullable;

/**
* Simple handler that invokes a {@link LoggingErrorHandler} for each record.
*
Expand All @@ -35,7 +37,7 @@ public class BatchLoggingErrorHandler implements BatchErrorHandler {
new LogAccessor(LogFactory.getLog(BatchLoggingErrorHandler.class));

@Override
public void handle(Exception thrownException, ConsumerRecords<?, ?> data) {
public void handle(Exception thrownException, @Nullable ConsumerRecords<?, ?> data) {
StringBuilder message = new StringBuilder("Error while processing:\n");
if (data == null) {
message.append("null ");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import org.apache.kafka.clients.consumer.Consumer;
import org.apache.kafka.clients.consumer.ConsumerRecords;

import org.springframework.lang.Nullable;

/**
* An error handler that has access to the consumer, for example to adjust
* offsets after an error.
Expand All @@ -31,7 +33,7 @@
public interface ConsumerAwareBatchErrorHandler extends BatchErrorHandler {

@Override
default void handle(Exception thrownException, ConsumerRecords<?, ?> data) {
default void handle(Exception thrownException, @Nullable ConsumerRecords<?, ?> data) {
throw new UnsupportedOperationException("Container should never call this");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public interface ErrorHandler extends GenericErrorHandler<ConsumerRecord<?, ?>>
*/
default void handle(Exception thrownException, List<ConsumerRecord<?, ?>> records, Consumer<?, ?> consumer,
MessageListenerContainer container) {
handle(thrownException, null); // NOSONAR
handle(thrownException, null);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

import org.apache.kafka.clients.consumer.Consumer;

import org.springframework.lang.Nullable;

/**
* A generic error handler.
*
Expand All @@ -35,7 +37,7 @@ public interface GenericErrorHandler<T> {
* @param thrownException The exception.
* @param data the data.
*/
void handle(Exception thrownException, T data);
void handle(Exception thrownException, @Nullable T data);

/**
* Handle the exception.
Expand Down