jaro-herod opened a new issue, #25837:
URL: https://github.com/apache/pulsar/issues/25837

   ### Search before reporting
   
   - [x] I searched in the [issues](https://github.com/apache/pulsar/issues) 
and found nothing similar.
   
   
   ### Read release policy
   
   - [x] I understand that [unsupported 
versions](https://pulsar.apache.org/contribute/release-policy/#supported-versions)
 don't get bug fixes. I will attempt to reproduce the issue on a supported 
version of Pulsar client and Pulsar broker.
   
   
   ### User environment
   
   Java Client Library : 
   ┌─────────┬───────────────────────────┐
   │ Version │ Bug present?              │
   ├─────────┼───────────────────────────┤
   │ 4.1.1   │ ✅ yes                    │
   ├─────────┼───────────────────────────┤
   │ 4.1.2   │ ✅ yes                    │
   ├─────────┼───────────────────────────┤
   │ 4.1.3   │ ✅ yes                    │
   ├─────────┼───────────────────────────┤
   │ 4.2.0   │ ✅ yes                    │
   ├─────────┼───────────────────────────┤
   │ 4.2.1   │ ✅ yes                    │
   ├─────────┼───────────────────────────┤
   │ master  │ ✅ yes (as of 2026-05-20) │
   └─────────┴───────────────────────────┘
   
   ### Issue Description
   
   Calling consumer.hasMessageAvailable() (or the async variant) on a consumer 
created via PulsarClient.newConsumer().subscribe() throws 
UnsupportedOperationException: Unknown MessageId type: null if called before 
any message has been dequeued.
   
   The exception propagates from MessageIdAdv.compareTo() when 
ConsumerImpl.hasMoreMessages() is called with a null startMessageId.
   
   
   ### Error messages
   
   ```text
   java.lang.UnsupportedOperationException: Unknown MessageId type: null
        at 
org.apache.pulsar.client.api.MessageIdAdv.compareTo(MessageIdAdv.java:106)
        at 
org.apache.pulsar.client.api.MessageIdAdv.compareTo(MessageIdAdv.java:29)
        at 
org.apache.pulsar.client.impl.ConsumerImpl.hasMoreMessages(ConsumerImpl.java:2805)
        at 
org.apache.pulsar.client.impl.ConsumerImpl.hasMessageAvailableAsync(ConsumerImpl.java:2757)
        at 
org.apache.pulsar.client.impl.ConsumerImpl.hasMessageAvailable(ConsumerImpl.java:2694)
   ```
   
   ### Reproducing the issue
   
   ```
    PulsarClient client = 
PulsarClient.builder().serviceUrl("pulsar://localhost:6650").build();
    
    Consumer<byte[]> consumer = client.newConsumer()
        .topic("persistent://my-tenant/my-ns/my-topic")
        .subscriptionName("my-sub")
        .subscriptionType(SubscriptionType.Exclusive)
        .subscribe();
    
    // Throws UnsupportedOperationException BEFORE any readNext() call:
    boolean hasMessages = consumer.hasMessageAvailable();
   ```
   Note: The exception does not occur if consumer.receive() / 
consumer.receive(timeout, unit) is called at least once first, because 
lastDequeuedMessageId is then non-earliest and hasMoreMessages takes a 
different code path.
   
   ### Additional information
   
   _No response_
   
   ### Are you willing to submit a PR?
   
   - [ ] I'm willing to submit a PR!


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

Reply via email to