gnodet-bot commented on code in PR #2326:
URL: https://github.com/apache/maven-resolver/pull/2326#discussion_r4631427895
##########
maven-resolver-api/src/main/java/org/eclipse/aether/transfer/ArtifactNotFoundException.java:
##########
@@ -37,6 +37,17 @@ public ArtifactNotFoundException(Artifact artifact,
RemoteRepository repository)
super(artifact, repository, getMessage(artifact, null, repository));
}
+ /**
+ * Creates a new exception with the specified artifact, repository and
root cause.
+ *
+ * @param artifact The missing artifact, may be {@code null}.
+ * @param repository The involved remote repository, may be {@code null}.
+ * @since 2.0.26
+ */
+ public ArtifactNotFoundException(Artifact artifact, RemoteRepository
repository, Throwable cause) {
Review Comment:
⚠️ **Missing `@param cause` in Javadoc.** The sibling
`MetadataNotFoundException(Metadata, RemoteRepository, Throwable)` documents
all three parameters; this constructor skips `@param cause`. Add:
```
* @param cause The error that caused the resolution failure, may be {@code
null}.
```
##########
maven-resolver-api/src/main/java/org/eclipse/aether/ConfigurationProperties.java:
##########
@@ -825,6 +825,24 @@ public enum HttpVersion {
*/
public static final boolean DEFAULT_INSTALLER_HARD_LINK = true;
+ /**
+ * A flag indicating whether HTTP transport should capture the response
body for non-RFC 9457 error responses.
+ * When enabled, the response body is captured and made available to the
caller, which can be
+ * useful for debugging and error reporting. When disabled, the response
body is discarded to save memory and
+ * improve performance.
+ * To disable capturing of RFC 9457 error responses, set {@link
#HTTP_SEND_RFC9457_ACCEPT} to {@code false}.
+ *
+ * @since 2.0.27
+ * @configurationSource {@link
RepositorySystemSession#getConfigProperties()}
+ * @configurationType {@link java.lang.Boolean}
+ * @configurationDefaultValue {@link
#DEFAULT_HTTP_CAPTURE_RESPONSE_BODY_FOR_ERRORS}
+ * @configurationRepoIdSuffix No
+ */
+ public static final String HTTP_CAPTURE_RESPONSE_BODY_FOR_ERRORS =
+ PREFIX_TRANSPORT_HTTP + "captureResponseBodyForErrors";
+
+ public static final boolean DEFAULT_HTTP_CAPTURE_RESPONSE_BODY_FOR_ERRORS
= false;
Review Comment:
⚠️ **Missing Javadoc on `DEFAULT_HTTP_CAPTURE_RESPONSE_BODY_FOR_ERRORS`.**
The property constant `HTTP_CAPTURE_RESPONSE_BODY_FOR_ERRORS` above has full
Javadoc; add at least a one-liner for the default value constant, e.g.:
```java
/**
* Default value for {@link #HTTP_CAPTURE_RESPONSE_BODY_FOR_ERRORS}:
{@value}.
*
* @since 2.0.27
*/
```
##########
maven-resolver-spi/src/main/java/org/eclipse/aether/spi/connector/transport/http/RFC9457/RFC9457Reporter.java:
##########
@@ -66,15 +97,21 @@ public abstract class RFC9457Reporter<T, E extends
Exception, R> {
public abstract void prepareRequest(R request);
/**
- * Reads the given stream into a UTF-8 string, consuming at most {@link
#MAX_BODY_BYTES} bytes.
+ * Reads the given stream into a string, consuming at most {@link
#MAX_BODY_BYTES} bytes.
* Any remaining bytes are left unread, so an oversized (or decompression
amplified) body is
* truncated instead of exhausting memory. The caller remains responsible
for closing the stream.
*
* @param is The stream to read the body from, must not be {@code null}.
+ * @param contentType The content type of the body, may be {@code null} if
unknown.
* @return The body as UTF-8 string, truncated to {@link #MAX_BODY_BYTES}
bytes, never {@code null}.
* @throws IOException If reading the stream fails.
*/
- protected static String readBody(InputStream is) throws IOException {
+ protected static String readBody(InputStream is, String contentType)
throws IOException {
Review Comment:
⚠️ **Stale `@return` on `readBody()`.** The Javadoc at line 106 says *"The
body as UTF-8 string"* but the implementation now calls
`extractCharsetFromContentType()` and can decode with any charset. Update to
reflect actual behaviour, e.g.: *"The body decoded using the content-type
charset (default UTF-8), truncated to `MAX_BODY_BYTES` bytes, never `null`"*.
##########
maven-resolver-spi/src/main/java/org/eclipse/aether/spi/connector/transport/http/RFC9457/RFC9457Reporter.java:
##########
@@ -49,12 +55,37 @@ public abstract class RFC9457Reporter<T, E extends
Exception, R> {
*/
public static final int MAX_BODY_BYTES = 64 * 1024;
- protected abstract boolean isRFC9457Message(T response);
+ private final boolean captureResponseBody;
+
+ /**
+ * Creates a new reporter.
+ *
+ * @param captureResponseBody Whether to capture the response body for
non-RFC 9457 messages. If false, the exception will not contain the body
extract.
+ */
+ protected RFC9457Reporter(boolean captureResponseBody) {
+ this.captureResponseBody = captureResponseBody;
+ }
+
+ /**
+ * Returns the content type of the response, or {@code null} if not
available.
+ * @param response The response to get the content type from.
+ * @return The content type of the response, or {@code null} if not
available, this should include optional parameters like charset.
Review Comment:
⚠️ **Run-on `@return` sentence.** The description mixes the return-value
contract (what `null` means) with an implementation note (charset parameter
inclusion) after a comma splice. Consider:
```
* @return The content type of the response, or {@code null} if not
available.
* When non-null, this may include parameters such as {@code
charset}.
```
##########
maven-resolver-spi/src/main/java/org/eclipse/aether/spi/connector/transport/http/HttpTransporterException.java:
##########
@@ -18,20 +18,63 @@
*/
package org.eclipse.aether.spi.connector.transport.http;
+import org.eclipse.aether.DebugMessageSupplier;
+
/**
- * Exception thrown by {@link HttpTransporter} in case of errors.
+ * Exception thrown by {@link HttpTransporter} in case of non 2xx responses.
*
* @since 2.0.0
*/
-public class HttpTransporterException extends Exception {
+public class HttpTransporterException extends Exception implements
DebugMessageSupplier {
private final int statusCode;
+ private final String reasonPhrase;
+ private final String bodyExtract;
public HttpTransporterException(int statusCode) {
- super("HTTP Status: " + statusCode);
+ super(buildMessage(statusCode, null));
+ this.statusCode = statusCode;
+ this.reasonPhrase = null;
+ this.bodyExtract = null;
+ }
+
+ public HttpTransporterException(int statusCode, String reasonPhrase) {
+ super(buildMessage(statusCode, reasonPhrase));
+ this.statusCode = statusCode;
+ this.reasonPhrase = reasonPhrase;
+ this.bodyExtract = null;
+ }
+
+ public HttpTransporterException(int statusCode, String reasonPhrase,
String bodyExtract) {
Review Comment:
⚠️ **Missing Javadoc on new public constructor.** Add a Javadoc block with
`@param statusCode`, `@param reasonPhrase`, `@param bodyExtract`, and `@since`.
##########
maven-resolver-spi/src/main/java/org/eclipse/aether/spi/connector/transport/http/RFC9457/RFC9457Reporter.java:
##########
@@ -21,23 +21,29 @@
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.nio.charset.Charset;
+import java.nio.charset.IllegalCharsetNameException;
import java.nio.charset.StandardCharsets;
+import java.nio.charset.UnsupportedCharsetException;
+import java.util.Locale;
+
+import
org.eclipse.aether.spi.connector.transport.http.HttpTransporterException;
/**
- * A reporter for RFC 9457 messages.
+ * A reporter for RFC 9457 messages with falling back to just reporting the
status code, reason phrase and a body extract if the response is not a RFC 9457
message.
Review Comment:
⚠️ **Class Javadoc first sentence is 40+ words.** Javadoc tools use the
first sentence (up to the first `.`) as the summary in generated indexes.
Consider ending the first sentence at *"RFC 9457 message"* and starting a new
sentence for the exception-class details.
##########
maven-resolver-spi/src/main/java/org/eclipse/aether/spi/connector/transport/http/HttpTransporterException.java:
##########
@@ -18,20 +18,63 @@
*/
package org.eclipse.aether.spi.connector.transport.http;
+import org.eclipse.aether.DebugMessageSupplier;
+
/**
- * Exception thrown by {@link HttpTransporter} in case of errors.
+ * Exception thrown by {@link HttpTransporter} in case of non 2xx responses.
*
* @since 2.0.0
*/
-public class HttpTransporterException extends Exception {
+public class HttpTransporterException extends Exception implements
DebugMessageSupplier {
private final int statusCode;
+ private final String reasonPhrase;
+ private final String bodyExtract;
public HttpTransporterException(int statusCode) {
- super("HTTP Status: " + statusCode);
+ super(buildMessage(statusCode, null));
+ this.statusCode = statusCode;
+ this.reasonPhrase = null;
+ this.bodyExtract = null;
+ }
+
+ public HttpTransporterException(int statusCode, String reasonPhrase) {
Review Comment:
⚠️ **Missing Javadoc on new public constructor.** Add a Javadoc block with
`@param statusCode`, `@param reasonPhrase`, and `@since`.
--
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]