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 |
T45K
left a comment
There was a problem hiding this comment.
@mirromutth
i updated this PR. could you check this again?
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#batchthis is because
StringBuilderinMySqlBatchingBatchis not initialized untiladdmethod is called.so,
executemethod will refer to not-initializedbuilderwhenaddmethod is not called.Modification:
(Please describe the changes you have made to the codebase, including any new files, modified files, or deleted files.)
modifyexecuteto returnFlux#emptywhenbuilderis not initialized (i.e.,addmethod 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.