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
Make static final buffers unreleasable and read-only #11802
Changes from all commits
4a8a855
4f3cf4c
2e301dd
977db3b
bde5357
644804d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,6 +44,7 @@ final class ReplayingDecoderByteBuf extends ByteBuf { | |
private boolean terminated; | ||
private SwappedByteBuf swapped; | ||
|
||
@SuppressWarnings("checkstyle:StaticFinalBuffer") // Unpooled.EMPTY_BUFFER is not writeable or readable. | ||
static final ReplayingDecoderByteBuf EMPTY_BUFFER = new ReplayingDecoderByteBuf(Unpooled.EMPTY_BUFFER); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See above There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto #11802 (comment) - it's a package-private static variable that wraps an instance of Though I wasn't able to find usages, maybe this one can be removed? Or did I miss it? |
||
|
||
static { | ||
|
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.
I guess we could also just call
asReadOnly()
and remove theSupressWarnings
?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.
Also we should ensure to wrap it in
unreleasableBuffer
to make it more "future proof"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.
That'd be an incompatible public API change.
EMPTY_BUFFER
is an instance ofEmptyByteBuf
(see static assert below).asReadOnly
wraps instance into theReadOnlyByteBuf
(andunreleasableBuffer
wraps in theUnreleasableByteBuf
). If instance type is changed it'll break any downstream dependency that doesinstanceof EmptyByteBuf
check.What you suggested was my initial implementation, but the assert below and
EmptyByteBuf
API guarantees that it's not readable nor writable. Functionally,asReadOnly
is not needed here, andSuppressWarnings
+ comment should be sufficient to document the expected behavior.Let me know if I misses something, or if you think comment should be more detailed.
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.
got it... ok yeah its ok then :)