You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Thomas Mortagne (JIRA)" <ji...@apache.org> on 2018/06/08 14:55:00 UTC

[jira] [Comment Edited] (IO-554) FileUtils.copyToFile(InputStream source, File destination) closes input stream

    [ https://issues.apache.org/jira/browse/IO-554?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16505803#comment-16505803 ] 

Thomas Mortagne edited comment on IO-554 at 6/8/18 2:54 PM:
------------------------------------------------------------

It does not make any sense to me to debate if an important regression like this one introduced in the previous version should be fixed... for retro compatibility reason. If you are using any library which use this API based on commons-io 2.5 or less, any upgrade of commons-io on your side will break it which is not really acceptable given commons-io standards.

I agree that behavior should not change but that's actually an argument for a bugfix release as fast as possible, not to keep a regression.


was (Author: tmortagne):
I does not make any sense to me to debate if an important regression like this one introduced in the previous version should be fixed... for retro compatibility reason. If you are using any library which use this API based on commons-io 2.5 or less, any upgrade of commons-io on your side will break it which is not really acceptable given commons-io standards.

I agree that behavior should not change but that's actually an argument for a bugfix release a fast as possible, not to keep a regression.

> FileUtils.copyToFile(InputStream source, File destination) closes input stream
> ------------------------------------------------------------------------------
>
>                 Key: IO-554
>                 URL: https://issues.apache.org/jira/browse/IO-554
>             Project: Commons IO
>          Issue Type: Bug
>          Components: Streams/Writers
>    Affects Versions: 2.6
>            Reporter: Michele Mariotti
>            Assignee: Bruno P. Kinoshita
>            Priority: Blocker
>              Labels: regression
>             Fix For: 2.7
>
>
> In 2.6 this method is closing the input stream, while the javadoc states the opposite.
> The correct behavior is to leave the stream open, as stated in the javadoc.
> I assigned a high priority because this incorrect behavior breaks existing code, especially when used in combination with ZipInputStream.
> {code:java}
> /**
>  * Copies bytes from an {@link InputStream} <code>source</code> to a file
>  * <code>destination</code>. The directories up to <code>destination</code>
>  * will be created if they don't already exist. <code>destination</code>
>  * will be overwritten if it already exists.
>  * The {@code source} stream is left open, e.g. for use with {@link java.util.zip.ZipInputStream ZipInputStream}.
>  * See {@link #copyInputStreamToFile(InputStream, File)} for a method that closes the input stream.
>  *
>  * @param source      the <code>InputStream</code> to copy bytes from, must not be {@code null}
>  * @param destination the non-directory <code>File</code> to write bytes to
>  *                    (possibly overwriting), must not be {@code null}
>  * @throws IOException if <code>destination</code> is a directory
>  * @throws IOException if <code>destination</code> cannot be written
>  * @throws IOException if <code>destination</code> needs creating but can't be
>  * @throws IOException if an IO error occurs during copying
>  * @since 2.5
>  */
> public static void copyToFile(final InputStream source, final File destination) throws IOException {
> 	try (InputStream in = source;
> 		 OutputStream out = openOutputStream(destination)) {
> 		IOUtils.copy(in, out);
> 	}
> }
> {code}
> instead it should be:
> {code:java}
> public static void copyToFile(final InputStream source, final File destination) throws IOException {
> 	try (OutputStream out = openOutputStream(destination)) {
> 		IOUtils.copy(source, out);
> 	}
> }{code}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)