apache/maven · error · IllegalArgumentException

Invalid request

Error message

Invalid request

What it means

IllegalArgumentException from the Maven API ProjectBuilder when a ProjectBuilderRequest carries neither a Path nor a Source — build() has nothing to read a model from. The request is built through ProjectBuilderRequest.build(...) functions; exactly one input (path to a pom, or an in-memory Source) must be set before calling the service.

Source

Thrown at impl/maven-core/src/main/java/org/apache/maven/internal/impl/DefaultProjectBuilder.java:96

        RequestTraceHelper.ResolverTrace trace = RequestTraceHelper.enter(request.getSession(), request);
        try {
            List<ArtifactRepository> repositories = session.toArtifactRepositories(
                    request.getRepositories() != null ? request.getRepositories() : session.getRemoteRepositories());
            ProjectBuildingRequest req = new DefaultProjectBuildingRequest()
                    .setRepositorySession(session.getSession())
                    .setRemoteRepositories(repositories)
                    .setPluginArtifactRepositories(repositories)
                    .setProcessPlugins(request.isProcessPlugins());
            ProjectBuildingResult res;
            if (request.getPath().isPresent()) {
                Path path = request.getPath().get();
                res = builder.build(path.toFile(), req);
            } else if (request.getSource().isPresent()) {
                Source source = request.getSource().get();
                ModelSource2 modelSource = new SourceWrapper(source);
                res = builder.build(modelSource, req);
            } else {
                throw new IllegalArgumentException("Invalid request");
            }
            return new ProjectBuilderResult() {
                @Override
                public ProjectBuilderRequest getRequest() {
                    return request;
                }

                @Nonnull
                @Override
                public String getProjectId() {
                    return res.getProjectId();
                }

                @Nonnull
                @Override
                public Optional<Path> getPomFile() {
                    return Optional.ofNullable(res.getPomFile()).map(File::toPath);
                }

View on GitHub (pinned to e4093d4e12)

Solutions

  1. Set a pom path: ProjectBuilderRequest.build(session, r -> r.path(Path.of("pom.xml")))
  2. Or supply a Source for in-memory models: ProjectBuilderRequest.build(session, r -> r.source(mySource))
  3. Assert request.getPath().isPresent() || request.getSource().isPresent() before invoking the builder

Example fix

// before
ProjectBuilderResult result = session.getService(ProjectBuilder.class)
    .build(ProjectBuilderRequest.build(session, r -> {})); // Invalid request

// after
ProjectBuilderResult result = session.getService(ProjectBuilder.class)
    .build(ProjectBuilderRequest.build(session, r -> r.path(Path.of("pom.xml"))));
Defensive patterns

Strategy: validation

Validate before calling

// Fail fast on an unusable request before calling the builder
if (request.getPath().isEmpty() && request.getSource().isEmpty()) {
    throw new IllegalArgumentException(
        "ProjectBuilderRequest needs a pom path or a Source; neither was set");
}

Prevention

When it happens

Trigger: Constructing ProjectBuilderRequest.build(session, r -> {}) without calling r.path(...) or r.source(...), then invoking ProjectBuilder.build(request); passing a default-constructed request from embedder or test code.

Common situations: Embedder/test code adopting the org.apache.maven.api services; refactors that drop or conditionally skip the path/source argument without a fallback branch.

Related errors


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