Skip to content

Wrong progress reported to ProgressListener by AbstractBoxMultipartRequest #1149

@ivan-ankov

Description

@ivan-ankov
  • I have checked that the [SDK documentation][sdk-docs] doesn't solve my issue.
  • I have checked that the [API documentation][api-docs] doesn't solve my issue.
  • I have searched the [Box Developer Forums][dev-forums] and my issue isn't already reported (or if it has been reported, I have attached a link to it, for reference).
  • I have searched [Issues in this repo][github-repo] and my issue isn't already reported.

Description of the Issue

The following code is just wrong in AbstractBoxMultipartRequest:

    public void writeTo(BufferedSink bufferedSink) throws IOException {
        byte[] buffer = new byte[BUFFER_SIZE];
        int n = this.inputStream.read(buffer);
        int totalWritten = n;
        while (n != -1) {
            bufferedSink.write(buffer, 0, n);
            if (progressListener != null) {
                progressListener.onProgressChanged(totalWritten, this.contentLength());
            }
            totalWritten += n;
            n = this.inputStream.read(buffer);
        }
    }

totalWritten is initialized with n and then incremented with the same n in the cycle, before n is updated.

Steps to Reproduce

  1. Upload a file larger than 8192 bytes (the upload buffer size) and set a progress listener
  2. At some point the listener will receive onProgressChanged() with numBytes > totalBytes

Expected Behavior

Progress reporting to be correct and to not exceed the size of the uploaded file

Metadata

Metadata

Labels

bugAdded to issues that describes SDK bugdontstaleMark issues not to be removed by stalebot

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions