You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@qpid.apache.org by "ASF subversion and git services (Jira)" <ji...@apache.org> on 2023/03/27 17:42:00 UTC

[jira] [Commented] (PROTON-2697) Receiver.receive() throws java.lang.IllegalArgumentException: timeout value is negative

    [ https://issues.apache.org/jira/browse/PROTON-2697?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17705476#comment-17705476 ] 

ASF subversion and git services commented on PROTON-2697:
---------------------------------------------------------

Commit 8e74916dac8455fa711a75d8f4cfab827e6f4d78 in qpid-protonj2's branch refs/heads/main from Timothy Bish
[ https://gitbox.apache.org/repos/asf?p=qpid-protonj2.git;h=8e74916d ]

PROTON-2697 Resolve exception if receive timeout is less than minus one

Accept all negative values as infinite wait to allow for unit
conversions that result in values lower than minus one causing an
exception on thread wait.

> Receiver.receive() throws java.lang.IllegalArgumentException: timeout value is negative
> ---------------------------------------------------------------------------------------
>
>                 Key: PROTON-2697
>                 URL: https://issues.apache.org/jira/browse/PROTON-2697
>             Project: Qpid Proton
>          Issue Type: Bug
>          Components: protonj2
>    Affects Versions: protonj2-1.0.0-M12
>            Reporter: Jiri Daněk
>            Assignee: Timothy A. Bish
>            Priority: Major
>
> I'm doing this
> {code}
>                 final Delivery delivery;
>                 delivery = receiver.receive(timeout, TimeUnit.SECONDS);
> {code}
> 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.
> {code}
> ClientDelivery delivery = deliveryQueue.dequeue(units.toMillis(timeout));
> {code}
> And I get exception.
> {noformat}
> 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)
> {noformat}
> 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.
> {noformat}
>     /**
>      * 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.
> [...]
> {noformat}
> 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.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@qpid.apache.org
For additional commands, e-mail: dev-help@qpid.apache.org