[jcifs] Issues with closing destination file in SmbFile.copyTo0()

Michael B Allen ioplex at gmail.com
Sun Jun 29 00:15:57 MDT 2014

On Fri, Jun 20, 2014 at 12:15 PM, Vella, Shon <svella at idauto.net> wrote:
> thread. When the writer thread did the write, it would fail with an
> Invalid Handle and exit the writer thread leaving a record of the
> exception. Subsequent writes to the writer thread (for all the rest of
> the files in a deep copy, which in this case was a lot) would fail
> because of the remembered exception, and because that remembered

Hi Shon,

Maybe try setting e = null just before the for loop in
WriterThread.run(). That will reset it for each new Thread. But I seem
to recall doing that previously so there might be an issue. If you try
it, let me know how it works out.

> exception would be thrown each time, the close of the file would be
> skipped and left open. My patch along with setting
> ignoreCopyToException to false completely fixes the problem I was
> happen, but there is still one issue remaining which is that if
> ignoreCopyToException is left at the default, an exception in the
> writer thread will not abort a deep copy, but rather continue to open
> destination files, fail to write to them and then close them leaving
> them empty.

Yeah, that's no good. You should not have to use ignoreCopyToException
= false to work-around. I think maybe resetting the exception might be
enough. Try it.

However, if there's a network connectivity issue, we probably don't
want to just get stuck trying to copy things without end. Each
operation could timeout and then the whole thing could just get
effectively stuck. The remembered exception probably ensures a speedy
exit in such a scenario. Not sure. SmbFile.copyTo on a deep directory
is such a big, sprawling operation, it may be difficult to satisfy
everyone's expectations. This is the sort of thing that we need to
just play around with and weigh the good vs the bad.

One possible improvement to Exception handling in copyTo might be to
allow the caller to supply an Exception handler that would just be a
class with a method like:

public interface CopyToExceptionHandler
  void onException(Exception e) throws Exception;

that would be called whenever an exception occurred. The caller could
then decide what to do like just logging something or rethrowing the
Exception (or a different Exception) which would then be thrown out of
copyTo and stopping the copy.


More information about the jCIFS mailing list