Skip to content

Delete redundant null check #3915

@ghgh415263

Description

@ghgh415263

Expected Behavior
null check once

Current Behavior
check twice

Context
DefaultKafkaProducerFactory class
method abortTransaction()
There are two null checks on the producerFailed variable.

		@Override
		public void abortTransaction() throws ProducerFencedException {
			LOGGER.debug(() -> toString() + " abortTransaction()");
			if (this.producerFailed != null) {
				LOGGER.debug(() -> {
					String message = this.producerFailed == null ? "" : this.producerFailed.getMessage();
					return "abortTransaction ignored - previous txFailed: " + message
							+ ": " + this;
				});
			}
			else {
				try {
					this.delegate.abortTransaction();
				}
				catch (RuntimeException e) {
					LOGGER.error(e, () -> "Abort failed: " + this);
					this.producerFailed = e;
					throw e;
				}
			}
		}

What do you think about changing it like this?

if (this.producerFailed != null) {
   LOGGER.debug(() -> "abortTransaction ignored - previous txFailed: " + this.producerFailed.getMessage()
            + ": " + this);
}

thanks for reading.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions