lhotari commented on pull request #10548:
URL: https://github.com/apache/pulsar/pull/10548#issuecomment-839754494


   > I tested this, and I'm still getting an NPE on this line:
   > `"mlName=" + ml != null ? ml.getName() : "null"`
   > Looks like `ml.getName()` is just returning `name`...
   > Any ideas?
   
   @devinbost  Code like `"mlName=" + ml != null ? ml.getName() : "null"` can 
fail when there isn't proper synchronization in place and the field has been 
modified by another thread.
   One workaround would be to store the field values into local variables and 
then do the null checks.
   Something like this:
   ```
       @Override
       public String toString() {
           ManagedLedgerImpl ml = this.ml;
           LedgerHandle ledger = this.ledger;
           return "OpAddEntry{"
                   + "mlName" + ml != null ? ml.getName() : "null"
                   + ", ledgerId=" + ledger != null ? 
String.valueOf(ledger.getId()) : "null"
                   + ", entryId=" + entryId
                   + ", startTime=" + startTime
                   + ", dataLength=" + dataLength
                   + '}';
       }
   ```
   
   
   
   
   


-- 
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.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to