Technoboy- commented on PR #15820:
URL: https://github.com/apache/pulsar/pull/15820#issuecomment-1140580986
> I'm not sure if it could solve the NPE. Is there a race condition like the
following code snippet I commented?
>
> ```java
> if (hasInactive && isEnabled()) { // 1. isEnabled() returns true,
managedCursor is not null
> // during 1 and 2, some other methods changed `managedCursor`
to null
> takeSnapshot(getManagedCursor().getMarkDeletedPosition()); //
2. managedCursor might be null
> ```
>
> I'd prefer the following way.
>
> ```java
> final ManagedCursor cursor = managedCursor;
> if (hasInactive && cursor != null) {
> takeSnapshot(cursor.getMarkDeletedPosition(), cursor);
> }
> ```
>
> ```java
> private void takeSnapshot(Position position) {
> takeSnapshot(position, getManagedCursor());
> }
>
> private void takeSnapshot(Position position, ManagedCursor cursor) {
> /* ... */
> cursor.asyncMarkDelete(position, snapshot, new
MarkDeleteCallback() {
> ```
Method `checkStatus` and `purgeInactiveProducers` is `synchonized`. Seems
no race condition.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]