ARM Blocks: ease of use and for loops

Howard Lovatt howard.lovatt at
Thu Nov 12 01:55:33 PST 2009

Reinier has raised a good point that you start with a CloseableIterable and
end up with just an Iterable, this loosing of the Cloaseable type hasn't
happened in my code (because I am looking for the problem). I can see that
it would happen in other peoples code and also by mistake. I think this
problem is solved by using:

try(final String line : iterableFile) {

The above try-for-each block will fail at compile time if iterableFile isn't
of type CloseableIterable.

Secondly, and more controversially, the for-each loop could fail at compile
time if given a CloseableIteratable as opposed to a normal Iterable.

2009/11/11 Reinier Zwitserloot <reinier at>

> The problem is: If you forget to retrofit a filter, or you're just using
> one written with java6 or below in mind, then there's no obvious sign that
> your resource is not being closed. No compiler error or warning. Not even a
> pattern in the code you can detect. You'll notice a month later, when you've
> released your product to your customers, who are starting to call in with
> strange errors involving full DB pools and such. The fix is to write up a
> custom findbugs plugin, or something similar. Given the way findbugs is not
> even close to universally used, let alone used with custom plugins, that is
> not at all a satisfactory answer.
> That's a very serious problem.
> --Reinier Zwitserloot
> On Wed, Nov 11, 2009 at 10:30 PM, Neal Gafter <neal at> wrote:
>> On Wed, Nov 11, 2009 at 1:21 PM, Reinier Zwitserloot <
>> reinier at> wrote:
>>> Unless all existing filters are rewritten to support Closeable, and their
>>> close methods do an instanceof check on the contained Iterator and pass on
>>> the close call if they are also ClosableIterators, I don't see how that's
>>> going to work.
>> That sounds like a workable approach.
> ______________________________________________________________________
> This email has been scanned by the MessageLabs Email Security System.
> For more information please visit
> ______________________________________________________________________

 -- Howard.

More information about the coin-dev mailing list