Open GoogleCodeExporter opened 9 years ago
Just a side note. Current implementation of @Cleanup cannot be used outside a
local variable declaration, like this:
public static void sample(InputStream in, String[] args) throws IOException {
@Cleanup in = new FileInputStream(args[0]);
in.read();
...
}
However even if @Cleanup was later expanded to support this example above, then
it would be still possible to implement the requested behavior, as follows:
public static void sample(InputStream in, String[] args) throws IOException {
in = new FileInputStream(args[0]);
boolean $pending_in = true;
try {
in.read();
...
if (in != null) {
$pending_in = false;
in.close();
}
} finally {
if ($pending_in && in != null) {
try {
in.close();
} catch (Throwable e) {
}
}
}
}
Otherwise I still recommend my previous suggestion.
Original comment by einar.saukas
on 19 Mar 2015 at 10:09
Original issue reported on code.google.com by
einar.saukas
on 19 Mar 2015 at 10:01