@@ -718,10 +718,8 @@ public <E extends Throwable> DbxEntry.File finishUploadFile(Uploader uploader, D
718
718
return uploader .finish ();
719
719
}
720
720
catch (NoThrowOutputStream .HiddenException ex ) {
721
- // We hid our OutputStream's IOException from their writer.write() function so that
722
- // we could properly raise a NetworkIOException if something went wrong with the
723
- // network stream.
724
- throw new NetworkIOException (ex .underlying );
721
+ if (ex .owner == streamWrapper ) throw new NetworkIOException (ex .getCause ());
722
+ throw ex ;
725
723
}
726
724
finally {
727
725
uploader .close ();
@@ -940,21 +938,29 @@ private <E extends Throwable> HttpRequestor.Response chunkedUploadCommon(String[
940
938
941
939
HttpRequestor .Uploader uploader = DbxRequestUtil .startPut (requestConfig , accessToken , USER_AGENT_ID , host .getContent (), apiPath , params , headers );
942
940
try {
941
+ NoThrowOutputStream nt = new NoThrowOutputStream (uploader .getBody ());
943
942
try {
944
- NoThrowOutputStream nt = new NoThrowOutputStream (uploader .getBody ());
943
+ // Any exceptions thrown by writer.write (e.g. IOException) are "owned" by
944
+ // the caller so let them propagate. We should only handle exceptions caused
945
+ // by our uploader OutputStream.
945
946
writer .write (nt );
946
- long bytesWritten = nt .getBytesWritten ();
947
- if (bytesWritten != chunkSize ) {
948
- throw new IllegalStateException ("'chunkSize' is " + chunkSize + ", but 'writer' only wrote " + bytesWritten + " bytes" );
949
- }
947
+ }
948
+ catch (NoThrowOutputStream .HiddenException ex ) {
949
+ if (ex .owner == nt ) throw new NetworkIOException (ex .getCause ());
950
+ throw ex ;
951
+ }
952
+
953
+ long bytesWritten = nt .getBytesWritten ();
954
+ if (bytesWritten != chunkSize ) {
955
+ throw new IllegalStateException ("'chunkSize' is " + chunkSize + ", but 'writer' only wrote " + bytesWritten + " bytes" );
956
+ }
957
+
958
+ try {
950
959
return uploader .finish ();
951
960
}
952
961
catch (IOException ex ) {
953
962
throw new NetworkIOException (ex );
954
963
}
955
- catch (NoThrowOutputStream .HiddenException ex ) {
956
- throw new NetworkIOException (ex .underlying );
957
- }
958
964
}
959
965
finally {
960
966
uploader .close ();
0 commit comments