GZipEncoding should throw IOException from close

Open Beginner friendly
#868 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
68/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
java
Domain
api

Research direction

Start at the GZipEncoding.encode method shown in the issue, focusing on the anonymous BufferedOutputStream.close override and its IOException handling. Confirm that an IOException from close is propagated rather than swallowed, then run the project's relevant tests and verify the failure is observable to callers.

Written by the indexing model from the issue text.

Description

type: cleanup

The close method below swallows IOExceptions. That seems unnecessary and dangerous.

public class GZipEncoding implements HttpEncoding {

  public String getName() {
    return "gzip";
  }

  public void encode(StreamingContent content, OutputStream out) throws IOException {
    // must not close the underlying output stream
    OutputStream out2 =
        new BufferedOutputStream(out) {
          @Override
          public void close() throws IOException {
            // copy implementation of super.close(), except do not close the underlying output
            // stream
            try {
              flush();
            } catch (IOException ignored) {
                // Nothing else we can do here
            }
          }
        };
    GZIPOutputStream zipper = new GZIPOutputStream(out2);
    content.writeTo(zipper);
    // cannot call just zipper.finish() because that would cause a severe memory leak
    zipper.close();
  }
}
Dominant language
Java
Stars
1.4k
Forks
473
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from googleapis/google-http-java-client

All issues in googleapis/google-http-java-client

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.