apache/maven · error · UnsupportedOperationException

Not yet implemented

Error message

Not yet implemented

What it means

Thrown by DefaultSession.toArtifactRepository() when the RemoteRepository argument is not a DefaultRemoteRepository. The method converts a consumer-API (org.apache.maven.api) RemoteRepository into the legacy ArtifactRepository, but only the default implementation carries the underlying Eclipse Resolver repository needed for the conversion. Any other implementation of the RemoteRepository interface hits the 'TODO' branch and fails with UnsupportedOperationException.

Source

Thrown at impl/maven-core/src/main/java/org/apache/maven/internal/impl/DefaultSession.java:240

        if (repository instanceof DefaultRemoteRepository defaultRemoteRepository) {
            org.eclipse.aether.repository.RemoteRepository rr = defaultRemoteRepository.getRepository();

            try {
                return mavenRepositorySystem.createRepository(
                        rr.getUrl(),
                        rr.getId(),
                        rr.getPolicy(false).isEnabled(),
                        rr.getPolicy(false).getUpdatePolicy(),
                        rr.getPolicy(true).isEnabled(),
                        rr.getPolicy(true).getUpdatePolicy(),
                        rr.getPolicy(false).getChecksumPolicy());

            } catch (Exception e) {
                throw new RuntimeException("Unable to create repository", e);
            }
        } else {
            // TODO
            throw new UnsupportedOperationException("Not yet implemented");
        }
    }
}

View on GitHub (pinned to e4093d4e12)

Solutions

  1. Only pass RemoteRepository instances obtained from the Session itself (session.getRemoteRepositories(), newResolutionRepository) so they are DefaultRemoteRepository
  2. If you wrap repositories, unwrap/delegate to the original DefaultRemoteRepository before calling toArtifactRepository
  3. In tests, construct DefaultRemoteRepository (or use the session factory) instead of mocking the interface
  4. If you genuinely need a custom RemoteRepository converted, raise it upstream — the branch is an explicit TODO and unimplemented

Example fix

// before
RemoteRepository custom = new MyRemoteRepository(...);
ArtifactRepository ar = session.toArtifactRepository(custom); // UnsupportedOperationException

// after
DefaultRemoteRepository dr = (DefaultRemoteRepository) session.getRemoteRepositories().get(0);
ArtifactRepository ar = session.toArtifactRepository(dr);
Defensive patterns

Strategy: validation

Validate before calling

// before calling session.toArtifactRepository(r)
if (!(repository instanceof org.apache.maven.internal.impl.DefaultRemoteRepository)) {
    throw new IllegalArgumentException("Unsupported RemoteRepository implementation: " + repository.getClass().getName());
}

Type guard

boolean isConvertible(org.apache.maven.api.repository.RemoteRepository r) {
    return r instanceof org.apache.maven.internal.impl.DefaultRemoteRepository;
}

Try / catch

try {
    ArtifactRepository ar = session.toArtifactRepository(r);
} catch (UnsupportedOperationException e) {
    // fall back: construct the legacy ArtifactRepository via ArtifactRepositoryFactory
}

Prevention

When it happens

Trigger: Calling session.toArtifactRepository(repository) with a hand-written or third-party implementation of org.apache.maven.api.repository.RemoteRepository (e.g., a test stub, a mock, or a wrapper created by a custom repository policy), instead of the DefaultRemoteRepository instances produced by DefaultSession.newResolutionRepository()/repository session factories.

Common situations: Embedding Maven and wrapping RemoteRepository objects to customize releases/snapshots policy; mocking RemoteRepository in unit tests; upgrading a library that previously accepted any implementation and now enforces the concrete type.

Related errors


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