Skip to content

Remove unnecessary expressions in AsyncItemWriter #4009

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

Closed

Conversation

ParadiseCHOI
Copy link
Contributor

  1. Modify unnecessary parameter expression, list.add(future.get()) to list.add(item)
  2. Modify unnecessary conditional expression, if (cause != null && cause instanceof Exception) to if (cause instanceof Exception)
  3. Add conditional expression when list is empty
1. Unwrapped future's value have alreay been assigned to the item variable. So, 'item' variable should be delivered instead of future.get() in the list.add method.

2. The getCause method of the Throwable Object returns null if the cause is nonexistent or unknown. And instanceOf operator always returns false if the object is null. So, 'cause != null' expression is unnecessary.

3. While looking at Future related to asynchronous processing, I found that it was in use in AsyncItem (Processor, Writer) of spring-batch.
Looking at the internal implementation, it was written in violation of the processor's default behavior, null return, so I modified the code so that if items are empty in AsyncItemWriter, nothing is returned.


delegate.write(list);

if (!list.isEmpty()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What to do with empty chunks is a decision to be made by the delegate writer, not the asynchronous item writer. A concrete example is that when the delegate logs a warning about receiving an empty chunk, with this change, the log message would disappear. The role of the async item writer is to unwrap Futures objects and pass them to the delegate writer without any modification or additional logic. I will omit this change from the PR.

@fmbenhassine fmbenhassine changed the title Add the conditional expression to prevent the processing 'delegate.write(list)' when list is empty in AsyncItemWriter Remove unnecessary expressions in AsyncItemWriter Sep 14, 2023
fmbenhassine pushed a commit that referenced this pull request Sep 14, 2023
@fmbenhassine
Copy link
Contributor

Rebased and merged as 48925f0. Thank you for your contribution!

@fmbenhassine fmbenhassine added pr-for: enhancement for: backport-to-5.0.x Issues that will be back-ported to the 5.0.x line labels Sep 14, 2023
@fmbenhassine fmbenhassine added this to the 5.1.0-M3 milestone Sep 14, 2023
fmbenhassine pushed a commit that referenced this pull request Oct 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
for: backport-to-5.0.x Issues that will be back-ported to the 5.0.x line in: infrastructure pr-for: enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants