On 3/1/11 1:46 AM, Alan Bateman wrote:
Stuart Marks wrote:
Here's a small webrev with changes to a handful of java.io tests to use TWR.

http://cr.openjdk.java.net/~smarks/reviews/7022624/webrev.0/

[snip]

* test/java/io/OutputStreamWriter/Encode.java

Pretty clearly a ServerSocket is a distinct resource from a Socket returned
from the accept() call. However, does Socket.getInputStream() represent a
distinct resource from the Socket? In this case it seemed most sensible to
unroll them into separate resource variables, but again I could go either way
on this.
I wouldn't bother but would instead reduce this down to three resources, maybe:

try (ServerSocket listener = ss;
      Socket s = listener.accept();
      BufferedReader reader = new BufferedReader(new
InputStreamReader(s.getInputStream()))
{
    ...
}

Sounds reasonable.

While you are there, I assume ss should be final. Also might be good to put a
try/finally around the encode at L50-52 to ensure that disconnect is called.

Yeah, both are a good idea.

Thanks.

s'marks

Reply via email to