-
Notifications
You must be signed in to change notification settings - Fork 21
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
Fix NPE issue when batch execution is called without any queries #207
Fix NPE issue when batch execution is called without any queries #207
Conversation
The
So we cannot return an empty
However, it seems like a code smell coming from |
thank you for confirming my PR!
sorry, i didn't know the spi spec 🙏
i think this is more reasonable. i'd like to rewrite in this way. (question) i think we can make - private StringBuilder builder;
+ private final StringBuilder builder = new StringBuilder(); and then, private StringBuilder requireBuilder() {
- if (builder == null) {
- return (builder = new StringBuilder());
- }
+ if (builder.length() == 0) {
+ return builder;
+ }
return builder.append(';');
} this looks better for me. what do you think? |
Hmmm, if we check only it is empty or not, consider following code: batch1.add(";").add("SELECT 1").execute()
batch2.add("").add("SELECT 1").execute()
batch3.add("SELECT 1").execute() There Maybe it would be simpler to refactor the entire |
i see. i'll update this PR later |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mirromutth
i updated this PR. could you check this again?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Motivation:
(Please describe the problem you are trying to solve, or the new feature you are trying to add.)
we're using this R2DBC client with jOOQ.
NPE occurs when we give empty list to
DSLContext#batch
this is because
StringBuilder
inMySqlBatchingBatch
is not initialized untiladd
method is called.so,
execute
method will refer to not-initializedbuilder
whenadd
method is not called.Modification:
(Please describe the changes you have made to the codebase, including any new files, modified files, or deleted files.)
modifyexecute
to returnFlux#empty
whenbuilder
is not initialized (i.e.,add
method is not called).send empty string to client without NPE
Result:
(Please describe the expected outcome of your changes, and any potential side effects or drawbacks.
If possible, please also include any relevant testing results.)
it now does not throw NPE
but returns empty flux instead.