You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Pito Salas <pi...@gmail.com> on 2005/06/16 14:16:33 UTC
[collections] commons.collections.buffer.BlockingBuffer throws BufferUnderflowException
commons.collections.buffer.BlockingBuffer throws
BufferUnderflowException
Why does that make sense? I would think that a BlockingBuffer cannot
underflow on a get().
Looking at the code for get() I see:
public Object get() {
synchronized (lock) {
while (collection.isEmpty()) {
try {
wait();
} catch (InterruptedException e) {
throw new BufferUnderflowException();
}
}
return getBuffer().get();
}
}
So, an InterruptedException is turned into a BufferUnderflowException.
Usually InterruptedException is just re-thrown. I don't understand
how to interpret the conversion to a BufferUnderflowException, and
whether I can / should safely ignore it.
Anyone?
Pito
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org
Re: [collections] commons.collections.buffer.BlockingBuffer throws BufferUnderflowException
Posted by Pito Salas <pi...@gmail.com>.
Stephen
Thanks; but certainly the BlockingBuffer should document this use of
BufferUnderflowException, as it is clearly a misnomer for what really
happened; I suppose you have to use an exception which was available
in the interface.
- Pito
On Jun 17, 2005, at 6:30 PM, Stephen Colebourne wrote:
> Pito Salas wrote:
>
>> commons.collections.buffer.BlockingBuffer throws
>> BufferUnderflowException
>> Why does that make sense? I would think that a BlockingBuffer
>> cannot underflow on a get().
>>
>
>
>> So, an InterruptedException is turned into a
>> BufferUnderflowException.
>> Usually InterruptedException is just re-thrown. I don't
>> understand how to interpret the conversion to a
>> BufferUnderflowException, and whether I can / should safely
>> ignore it.
>>
>
> Buffer.get() can throw the underflow exception, as documented:
> @throws BufferUnderflowException if the buffer is empty
>
> For BlockingBuffer, you would not normally expect to receive the
> underflow exception as the class waits for more data. However, if
> it receives an interrupted exception while waiting we must handle
> it. We could:
> a) silently ignore it (bad)
> b) log it (but collections doesn't use logging)
> c) throw it
>
> We chose (c), and as InterruptedException is not runtime, it is
> wrapped in a BufferUnderflowException.
>
> You ask if you will receive it. Well, you will if you get a
> InterruptedException during the wait. I can't really be more
> precise than that.
>
> Stephen
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org
Re: [collections] commons.collections.buffer.BlockingBuffer throws
BufferUnderflowException
Posted by Stephen Colebourne <sc...@btopenworld.com>.
Pito Salas wrote:
> commons.collections.buffer.BlockingBuffer throws BufferUnderflowException
>
> Why does that make sense? I would think that a BlockingBuffer cannot
> underflow on a get().
> So, an InterruptedException is turned into a BufferUnderflowException.
>
> Usually InterruptedException is just re-thrown. I don't understand how
> to interpret the conversion to a BufferUnderflowException, and whether
> I can / should safely ignore it.
Buffer.get() can throw the underflow exception, as documented:
@throws BufferUnderflowException if the buffer is empty
For BlockingBuffer, you would not normally expect to receive the
underflow exception as the class waits for more data. However, if it
receives an interrupted exception while waiting we must handle it. We could:
a) silently ignore it (bad)
b) log it (but collections doesn't use logging)
c) throw it
We chose (c), and as InterruptedException is not runtime, it is wrapped
in a BufferUnderflowException.
You ask if you will receive it. Well, you will if you get a
InterruptedException during the wait. I can't really be more precise
than that.
Stephen
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org