Copilot commented on code in PR #15809:
URL: https://github.com/apache/grails-core/pull/15809#discussion_r3509561079
##########
grails-wrapper/src/main/java/grails/init/GrailsUpdater.java:
##########
@@ -329,17 +331,62 @@ private String fetchSnapshotForVersion(GrailsWrapperRepo
repo, GrailsVersion bas
}
}
- private static HttpURLConnection createHttpURLConnection(String
mavenMetadataFileUrl) throws IOException {
- final URL url;
+ static HttpURLConnection createHttpURLConnection(String
mavenMetadataFileUrl) throws IOException {
+ URI uri = createSecureRemoteUri(mavenMetadataFileUrl);
+ for (int redirectCount = 0; redirectCount <= MAX_REDIRECTS;
redirectCount++) {
+ URL url = uri.toURL();
+ HttpURLConnection conn = (HttpURLConnection) url.openConnection();
+ conn.setRequestProperty("User-Agent", "Apache-Maven/3.9.6");
+ conn.setInstanceFollowRedirects(false);
+
+ int responseCode = conn.getResponseCode();
+ if (!isRedirect(responseCode)) {
+ return conn;
+ }
+
+ String location = conn.getHeaderField("Location");
+ conn.disconnect();
+ uri = resolveSecureRedirectUrl(uri, location);
+ }
+
+ throw new IOException("Too many redirects while downloading Grails
wrapper artifact: " + mavenMetadataFileUrl);
+ }
Review Comment:
The exception message mentions "wrapper artifact", but this helper is also
used for Maven metadata downloads (see `retrieveMavenMetadata`). If this
triggers while fetching metadata, the message is misleading.
##########
grails-wrapper/src/test/groovy/grails/init/GrailsUpdaterSpec.groovy:
##########
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package grails.init
+
+import spock.lang.Specification
+import spock.lang.Unroll
+
Review Comment:
`URI` is used in this spec but not imported, and Groovy’s default imports
don’t include `java.net.*`. This will fail to compile.
##########
grails-wrapper/src/main/java/grails/init/GrailsUpdater.java:
##########
@@ -329,17 +331,62 @@ private String fetchSnapshotForVersion(GrailsWrapperRepo
repo, GrailsVersion bas
}
}
- private static HttpURLConnection createHttpURLConnection(String
mavenMetadataFileUrl) throws IOException {
- final URL url;
+ static HttpURLConnection createHttpURLConnection(String
mavenMetadataFileUrl) throws IOException {
+ URI uri = createSecureRemoteUri(mavenMetadataFileUrl);
+ for (int redirectCount = 0; redirectCount <= MAX_REDIRECTS;
redirectCount++) {
+ URL url = uri.toURL();
Review Comment:
The redirect loop uses `redirectCount <= MAX_REDIRECTS`, which actually
permits `MAX_REDIRECTS + 1` redirect responses before failing. If
`MAX_REDIRECTS` is intended to be a hard cap (as the name suggests), this
should be `< MAX_REDIRECTS`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]