Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix getPreviousPosition npe (apache#11621)
Fixes apache#11619 ### Motivation There's a chance that headMap might be empty even if a empty check added. because remove would be executed in ledgers. after the empty check between line 3214 and line 3219 in following code snippet: headMap is a view of ledgers pulsar/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedLedgerImpl.java Lines 3206 to 3222 in 31231d6 ``` NavigableMap<Long, LedgerInfo> headMap = ledgers.headMap(position.getLedgerId(), false); if (headMap.isEmpty()) { // There is no previous ledger, return an invalid position in the current ledger return PositionImpl.get(position.getLedgerId(), -1); } // We need to find the most recent non-empty ledger for (long ledgerId : headMap.descendingKeySet()) { LedgerInfo li = headMap.get(ledgerId); if (li.getEntries() > 0) { return PositionImpl.get(li.getLedgerId(), li.getEntries() - 1); } } // in case there are only empty ledgers, we return a position in the first one return PositionImpl.get(headMap.firstEntry().getKey(), -1); ``` ### Modifications Add a null checker of headMap.firstEntry Verifying this change Make sure that the change passes the CI checks. This change is a trivial rework / code cleanup without any test coverage. Co-authored-by: gavingaozhangmin <[email protected]>
- Loading branch information