Skip to content

Gradle wrapper ignores HTTP status code when downloading wrapper zip #6557

@reegnz

Description

@reegnz

Expected Behavior

When the wrapper URL returns a status code other than 200 OK the download should fail fast and not save the body of the response to the wrapper cache (~/.gradle/wrapper/dists) and shouldn't even try to unzip anything.
The wrapper should exit with a clear message of "Download failed with HTTP xxx status code".

Current Behavior

If the URL of the wrapper returns with a non 200 HTTP response, I get the error described in #6033.
The wrapper download doesn't check the status code of the response with https://docs.oracle.com/javase/7/docs/api/java/net/HttpURLConnection.html#getResponseCode() to fail fast on an HTTP status code other than 200.

Context

In #6033 I've explained the use-case of gradle not following HTTP redirects from HTTP to HTTPS.
When the url returns a 302 it will still save the response body as if it were a zip file, and tries to unzip it.
Further runs don't even try to download and try to unzip the corrupted zip file in the wrapper cache (dists folder).
It would be much better if gradle would fail fast by checking the response code before saving anything to a file.

The issue is around here:
https://github.com/gradle/gradle/blob/master/subprojects/wrapper/src/main/java/org/gradle/wrapper/Download.java#L66

Steps to Reproduce (for bugs)

About the same as in #6033

Your Environment

gradle 4.9 with Java 8.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions