Fix ObjectOutput handling of top-level scalar responses#3861
Conversation
| private void setValue(Object value) { | ||
|
|
||
| if (!initialized) { | ||
| output = new ArrayList<>(); |
There was a problem hiding this comment.
Shouldn't we assign the actual value here ?
There was a problem hiding this comment.
Thanks! Updated accordingly.
Top-level RESP3 scalar values are now assigned directly to output instead of being wrapped in a List.
| private void setValue(Object value) { | ||
|
|
||
| if (!initialized) { | ||
| output = new ArrayList<>(); |
There was a problem hiding this comment.
If value is non-collection type, could we not initialize output as a List? Instead, just assign value to ouput?
There was a problem hiding this comment.
Thanks for the suggestion!
Updated the implementation to assign top-level non-collection RESP3 values directly to output.
Nested collection responses are unchanged because multi() / multiMap() still initialize the collection container before nested values are accumulated.
I also added regression tests covering top-level bulk string, boolean, double, and integer responses.
Fixes #3860
Summary
ObjectOutputinitialized its top-level result withCollections.emptyList().When a top-level scalar response (for example, a bulk string returned from
EVALwithScriptOutputType.OBJECT) was decoded,setValue(...)attemptedto append to the immutable list, resulting in an
UnsupportedOperationException.This change lazily initializes a mutable list when the first top-level scalar
value is received, preserving the existing behavior for nested collections.
Tests
Validation
mvn test -Dtest=ObjectOutputUnitTestsgit diff --checkNote
Low Risk
Small, localized change to RESP3 decoding with new unit tests; nested map/list behavior is unchanged.
Overview
Fixes top-level scalar RESP3 responses (e.g. bulk strings from
EVALwithScriptOutputType.OBJECT) that previously crashed withUnsupportedOperationExceptionbecause the decoder tried to append the first value to the immutable placeholder list fromCollections.emptyList().ObjectOutputnow assigns the first decoded value directly tooutputand marks initialization complete, instead of creating anArrayListon integerset()and appending. Nested arrays/maps still use the existingmulti/multiMappaths unchanged.Regression coverage adds unit tests for top-level bulk string, boolean, double, and integer decoding via
RedisStateMachine.Reviewed by Cursor Bugbot for commit eb1b5c0. Bugbot is set up for automated code reviews on this repo. Configure here.