Conversation
| } finally { | ||
| if (reader != null) | ||
| reader.close(); | ||
| in.close(); |
There was a problem hiding this comment.
Why the change to close the passed SeekableInput? Shouldn't that be up to the caller?
There was a problem hiding this comment.
You're right, it should be closed by the caller but it is already implemented this way as we are closing the reader which closes the SeekableInput as well. I did not want to break backward compatibility but fix the actual situation that the resources are not closed every time.
That's why I've tried to highlight in the method comment that this method closes the specified SeekableInput.
There was a problem hiding this comment.
Can we update DataFileReader to properly not close the passed input stream instead?
There was a problem hiding this comment.
We can but it would be a backward incompatible change as this method is public.
If we would like to follow the usual pattern for this case we would need another method which does not close it and deprecate this one then remove this one in the next major release.
Or is it enough marking this JIRA with "incompatible change" and change as you are suggesting?
| if (args.size() == 2 && ! "-".equals(args.get(1))) { | ||
| parseOut = new PrintStream(new FileOutputStream(args.get(1))); | ||
| } | ||
| if (args.size() == 2 && !"-".equals(args.get(1))) { |
There was a problem hiding this comment.
it looks like these indents are incorrect.
There was a problem hiding this comment.
Seems you're right. I'll check it out.
| for (int i = in.read(buffer); i != -1; i = in.read(buffer)) | ||
| System.err.write(buffer, 0, i); | ||
| } finally { | ||
| in.close(); |
There was a problem hiding this comment.
Why are we closing in within this method instead of having the caller do it?
There was a problem hiding this comment.
This one is a private method and it seemed to be easier and shorter to close the stream inside this method instead of the public caller. Do you think I should rewrite it?
There was a problem hiding this comment.
yeah please have the caller close it instead. we should be internally disciplined.
There was a problem hiding this comment.
Fair enough. On the way...
|
@busbey, could you check my answers, please? |
| } finally { | ||
| if (reader != null) | ||
| reader.close(); | ||
| in.close(); |
There was a problem hiding this comment.
Can we update DataFileReader to properly not close the passed input stream instead?
| for (int i = in.read(buffer); i != -1; i = in.read(buffer)) | ||
| System.err.write(buffer, 0, i); | ||
| } finally { | ||
| in.close(); |
There was a problem hiding this comment.
yeah please have the caller close it instead. we should be internally disciplined.
c020505 to
73711e6
Compare
|
@busbey, could you please check the latest changes? |
| return appendTo(new SeekableFileInput(file), | ||
| new SyncableFileOutputStream(file, true)); | ||
| SeekableInput input = new SeekableFileInput(file); | ||
| OutputStream output = new SyncableFileOutputStream(file, true); |
There was a problem hiding this comment.
I think this line should be inside the try block as well to guarantee that input is always closed. Or, alternatively, it may be before the first line if order does not matter.
| try { | ||
| return appendTo(input, output); | ||
| } finally { | ||
| input.close(); |
There was a problem hiding this comment.
Could you please add a comment about why output does not have to be closed?
There was a problem hiding this comment.
good point. Will do it.
| } | ||
|
|
||
| /** Open a writer appending to an existing file. | ||
| * <strong>Since 1.9.0 this method does not close in.</strong> |
There was a problem hiding this comment.
1.9.0 is already out. Additionally, isn't this an API breaking change?
There was a problem hiding this comment.
Yes, unfortunately, this changes didn't make 1.9.0. And yes, this is an API breaking change so the next target is 1.10.0. Will rewrite the comment.
There was a problem hiding this comment.
1.9.0 isn't out yet afaik, so this should be fine as is.
There was a problem hiding this comment.
Ah, sorry, I was thinking of Parquet... :(
There was a problem hiding this comment.
Yes, that was my mistake too :)
| if (fw != null) | ||
| fw.close(); | ||
| if (fos != null) | ||
| fos.close(); |
There was a problem hiding this comment.
It seems to me that the second close() may not be called if the first one throws an IOException.
There was a problem hiding this comment.
fos.close() is invoked separately to close the file in case of the fw creation fails (fw starts writing at the constructor). If both fos and fw creation was successful than a problem occurs during writing fw.close() shall close the file. If it fails, fos.close() would probably fail too.
| @@ -55,8 +56,12 @@ private Json() {} // singleton: no public ctor | |||
| public static final Schema SCHEMA; | |||
| static { | |||
| try { | |||
There was a problem hiding this comment.
Do we have to support Java 1.6 in Avro, or we require 1.7+? I'm wondering if we can use try-with-resource statements instead of closing the stream in finally. Also, can we merge the two nested try{} blocks into one?
There was a problem hiding this comment.
Currently, Avro supports 1.6 so we are not able to use try-with-resources, unfortunately.
There was a problem hiding this comment.
We could start discussing dropping 1.6 support in the 1.9.0 release on the dev list.
|
Pushed another update (hopefully, the last one). |
busbey
left a comment
There was a problem hiding this comment.
please be sure to squash into a single commit with an appropriate commit message. otherwise LGTM.
Fixes for some unreleased resource issues found by static code analyzer tool.