You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2022/07/05 06:33:26 UTC

[GitHub] [pulsar] BewareMyPower commented on a diff in pull request #16392: [fix][broker]fix npe when filterEntriesForConsumer

BewareMyPower commented on code in PR #16392:
URL: https://github.com/apache/pulsar/pull/16392#discussion_r913430722


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/AbstractBaseDispatcher.java:
##########
@@ -127,7 +127,7 @@ public int filterEntriesForConsumer(Optional<MessageMetadata[]> optMetadataArray
         List<PositionImpl> entriesToRedeliver = CollectionUtils.isNotEmpty(entryFilters) ? new ArrayList<>() : null;
         for (int i = 0, entriesSize = entries.size(); i < entriesSize; i++) {
             Entry entry = entries.get(i);
-            if (entry == null) {
+            if (entry == null || entry.getDataBuffer() == null) {

Review Comment:
   First, it's better to check `metadataAndPayload == null` to reduce one more invocation of `getDataBuffer()`.
   
   Then, we should not resolve this issue by just adding a null check. `entry.getDataBuffer() == null` represents this entry has already been recycled. However, the corresponding item of a recycled entry in the entry list (`entries`) is usually set null, for example:
   
   https://github.com/apache/pulsar/blob/926834ef8b2b57d3964aa7e9773e6245bcee861c/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/AbstractBaseDispatcher.java#L142-L143
   
   Instead of null check simply, we should figure out in which case could `entries.get(i)` return a non-null entry that is recycled. In addition, I found your Pulsar version is 2.8.1.2, you might check the 2.8.1.2 source code first because there were many changes in master since that.



-- 
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: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org