Uploaded image for project: 'Qpid Proton'
  1. Qpid Proton
  2. PROTON-2697

Receiver.receive() throws java.lang.IllegalArgumentException: timeout value is negative



    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • protonj2-1.0.0-M12
    • protonj2-1.0.0-M13
    • protonj2
    • None


      I'm doing this

                      final Delivery delivery;
                      delivery = receiver.receive(timeout, TimeUnit.SECONDS);

      The problem is that protonj2 does the unit transform before checking for the -1 timeout magic value, so I end up passing -1000 and not -1 to it.

      ClientDelivery delivery = deliveryQueue.dequeue(units.toMillis(timeout));

      And I get exception.

      java.lang.IllegalArgumentException: timeout value is negative
      	at java.base/java.lang.Object.wait(Native Method)
      	at org.apache.qpid.protonj2.client.util.FifoDeliveryQueue.dequeue(FifoDeliveryQueue.java:90)
      	at org.apache.qpid.protonj2.client.impl.ClientReceiver.receive(ClientReceiver.java:70)
      	at com.redhat.mqe.CliProtonJ2Receiver.call(CliProtonJ2Receiver.java:268)

      I was following the doc comment for the Receiver.receive() method, which did not provide me with a hint that the TimeUnit has to be TimeUnit.MILLISECONDS for the magic value to work correctly.

           * Blocking receive method that waits the given time interval for the remote to provide a
           * {@link Delivery} for consumption.  The amount of time this method blocks is based on the
           * timeout value. If timeout is equal to <code>-1</code> then it blocks until a Delivery is
           * received. If timeout is equal to zero then it will not block and simply return a
           * {@link Delivery} if one is available locally.  If timeout value is greater than zero then it
           * blocks up to timeout amount of time.

      I suggest either explaining in the docs that only -1 MILLISECONDS work this way, or doing the -1 check before the TimeUnit is applied, so that -1 of any TimeUnit works.




            tabish Timothy A. Bish
            jdanek Jiri Daněk
            0 Vote for this issue
            2 Start watching this issue