-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Fix NPE when create OpEntry #12396
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 when create OpEntry #12396
Changes from all commits
fb160b3
9a33f24
942de2c
bd3ad18
ccbc70f
de5dc15
58c9db6
c814309
2320fa0
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 |
|---|---|---|
|
|
@@ -2154,6 +2154,7 @@ PositionImpl startReadOperationOnLedger(PositionImpl position, OpReadEntry opRea | |
| if (null == ledgerId) { | ||
| opReadEntry.readEntriesFailed(new ManagedLedgerException.NoMoreEntriesToReadException("The ceilingKey(K key) method is used to return the " + | ||
| "least key greater than or equal to the given key, or null if there is no such key"), null); | ||
|
Member
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. still npe, can't pass on null ctx, in the process of callback, need use it. |
||
| return null; | ||
| } | ||
|
|
||
| if (ledgerId != position.getLedgerId()) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,7 +48,6 @@ class OpReadEntry implements ReadEntriesCallback { | |
| public static OpReadEntry create(ManagedCursorImpl cursor, PositionImpl readPositionRef, int count, | ||
| ReadEntriesCallback callback, Object ctx, PositionImpl maxPosition) { | ||
| OpReadEntry op = RECYCLER.get(); | ||
| op.readPosition = cursor.ledger.startReadOperationOnLedger(readPositionRef, op); | ||
| op.cursor = cursor; | ||
| op.count = count; | ||
| op.callback = callback; | ||
|
|
@@ -58,6 +57,11 @@ public static OpReadEntry create(ManagedCursorImpl cursor, PositionImpl readPosi | |
| } | ||
| op.maxPosition = maxPosition; | ||
| op.ctx = ctx; | ||
| PositionImpl position = cursor.ledger.startReadOperationOnLedger(readPositionRef, op); | ||
| if (position == null) { | ||
| return null; | ||
|
Contributor
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. We can recycle this OpReadEntry if we return null.
Contributor
Author
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. My point is :
Contributor
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. +1
Member
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. It might be better to skip recycling of failed entries. That was something that was recently removed for OpAddEntry instances in #12993.
Member
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. yes, I guess |
||
| } | ||
| op.readPosition = position; | ||
| op.nextReadPosition = PositionImpl.get(op.readPosition); | ||
| return op; | ||
| } | ||
|
|
||
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.
Could you please provide more information about why op could be null?
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.
@codelipenghui This PR is used to solve NPE, is a copy of #11813 .
If op is null, the read faild event would be trigger.
There is another solution, see #11292 .
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.
It will be very dangerous if the dispatcher call read entries but can't receive any response, I think the broker will stop dispatching messages.