trying out the prototype (original) (raw)

Gernot Neppert mcnepp02 at googlemail.com
Tue Aug 24 02:27:20 PDT 2010


Hello,

first of all I have to say that as a long-time advocate of some kind of ARM in Java I'm thrilled to finally see it in action!

I've toyed with the latest snapshot and have 2 remarks:

  1. If you initialize a Resource that can only throw on close(), you get a compiler error that might be confusing because the automatic invocation of close() is invisible to the person writing the code. Here's a not-so-useful example that nevertheless exhibits the aforementioned behaviour:

try (Reader rdr = new StringReader("Some text")) { }

  1. If you use multiple Resources, an exception thrown by one of them will suppress exceptions thrown by the 'close()' invocation of others. While I can see some sense in suppressing exceptions from 'close()' of the same instance, I cannot see why this reasoning should apply to other instances. (I guess this forms a case against the try-with-multiple-resources statement in general. The list of semicolon-delimited declarations enclosed by parentheses looks weird, anyway ;-) Here's an example:

class ThrowsOnRead extends Reader { public int read(char[] cbuf, int off, int len) throws IOException { throw new IOException(); }

@Override
public void close() throws IOException
   {
    
   }

}

class ThrowsOnClose extends Reader { public void close() throws IOException { throw new IOException(); }

public int read(char[] cbuf, int off, int len) throws IOException

{ return 0; } }

public class TestAutoClose {

public static void main(String[] args) throws IOException {
    try(Reader rdr1 = new ThrowsOnRead(); Reader rdr2 = new ThrowsOnClose())
    {
        rdr1.read();  // Why is this exception more important than the

one thrown by rdr2.close() ? } } }



More information about the coin-dev mailing list