apache/maven · error · IllegalArgumentException

Illegal request type: " + requestType

Error message

Illegal request type: " + requestType

What it means

Thrown by ArtifactTransferEvent.setRequestType() when the supplied type is neither TransferEvent.REQUEST_GET nor TransferEvent.REQUEST_PUT. This legacy event object validates its int constants through a switch with a default arm; any other int (including 0, the field default) is rejected with IllegalArgumentException naming the value. It guards event-consumer APIs (progress monitors, listeners) against meaningless request types.

Source

Thrown at compat/maven-compat/src/main/java/org/apache/maven/repository/ArtifactTransferEvent.java:138

        return requestType;
    }

    /**
     * Sets the request type
     *
     * @param requestType The requestType to set.
     *                    The Request type value should be either
     *                    <code>TransferEvent.REQUEST_GET</code> or <code>TransferEvent.REQUEST_PUT</code>.
     * @throws IllegalArgumentException when
     */
    public void setRequestType(final int requestType) {
        switch (requestType) {
            case REQUEST_PUT:
                break;
            case REQUEST_GET:
                break;
            default:
                throw new IllegalArgumentException("Illegal request type: " + requestType);
        }

        this.requestType = requestType;
    }

    /**
     * @return Returns the eventType.
     */
    public int getEventType() {
        return eventType;
    }

    /**
     * @param eventType The eventType to set.
     */
    public void setEventType(final int eventType) {
        switch (eventType) {
            case TRANSFER_INITIATED:

View on GitHub (pinned to e4093d4e12)

Solutions

  1. Always pass the constants: TransferEvent.REQUEST_GET or TransferEvent.REQUEST_PUT
  2. Audit call sites that build events for swapped arguments (requestType vs eventType are both ints)
  3. Initialize requestType in the constructor rather than leaving 0 and setting later
  4. Prefer the consumer-era org.eclipse.aether.TransferEvent API in new code; this legacy class is deprecated

Example fix

// before
event.setRequestType(event.getRequestType()); // or an unset 0 leaks in
event.setRequestType(someEventType);           // swapped argument
// after
import static org.apache.maven.wagon.events.TransferEvent.REQUEST_GET;
event.setRequestType(REQUEST_GET);
Defensive patterns

Strategy: validation

Validate before calling

static boolean isValidRequestType(int t) {
    return t == org.apache.maven.wagon.events.TransferEvent.REQUEST_GET
        || t == org.apache.maven.wagon.events.TransferEvent.REQUEST_PUT;
}
if (!isValidRequestType(requestType)) throw new IllegalArgumentException("..." );

Prevention

When it happens

Trigger: Constructing an ArtifactTransferEvent or calling setRequestType() with a raw int other than the two constants - e.g. passing eventType (0-4 range) where requestType is expected, or a default-initialized 0 leaked from a partially built event.

Common situations: Custom TransferListener implementations or wagon bridges creating events by hand; copy-paste swaps of setEventType/setRequestType arguments; deserialized/partial event objects whose requestType field was never set and is re-assigned via the setter.

Related errors


AI-assisted analysis of apache/maven@e4093d4e12 (2026-08-21). Data as JSON: /api/errors/fd5d98f6f48b753d. Report an issue: GitHub.