{"record":{"id":"fc49444264cc4d06","repo":"apache/maven","slug":"unsupported-artifact-class","errorCode":null,"errorMessage":"Unsupported Artifact class: ","messagePattern":"Unsupported Artifact class: ","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"impl/maven-impl/src/main/java/org/apache/maven/impl/AbstractSession.java","lineNumber":270,"sourceCode":"    }\n\n    @SuppressWarnings(\"unchecked\")\n    @Override\n    public <T extends Artifact> T getArtifact(Class<T> clazz, org.eclipse.aether.artifact.Artifact artifact) {\n        Cache<org.eclipse.aether.artifact.Artifact, Artifact> map = allArtifacts.computeIfAbsent(\n                clazz, c -> Cache.newCache(Cache.ReferenceType.WEAK, \"AbstractSession-Artifacts-\" + c.getSimpleName()));\n        if (clazz == Artifact.class) {\n            return (T) map.computeIfAbsent(artifact, a -> new DefaultArtifact(this, a));\n        } else if (clazz == DownloadedArtifact.class) {\n            if (artifact.getPath() == null) {\n                throw new IllegalArgumentException(\"The given artifact is not resolved\");\n            } else {\n                return (T) map.computeIfAbsent(artifact, a -> new DefaultDownloadedArtifact(this, a));\n            }\n        } else if (clazz == ProducedArtifact.class) {\n            return (T) map.computeIfAbsent(artifact, a -> new DefaultProducedArtifact(this, a));\n        } else {\n            throw new IllegalArgumentException(\"Unsupported Artifact class: \" + clazz);\n        }\n    }\n\n    @Nonnull\n    @Override\n    public Dependency getDependency(@Nonnull org.eclipse.aether.graph.Dependency dependency) {\n        return allDependencies.computeIfAbsent(dependency, d -> new DefaultDependency(this, d));\n    }\n\n    @Override\n    public List<org.eclipse.aether.repository.RemoteRepository> toRepositories(List<RemoteRepository> repositories) {\n        return repositories == null ? null : map(repositories, this::toRepository);\n    }\n\n    @Override\n    public List<org.eclipse.aether.repository.RemoteRepository> toResolvingRepositories(\n            List<RemoteRepository> repositories) {\n        return getRepositorySystem().newResolutionRepositories(getSession(), toRepositories(repositories));","sourceCodeStart":252,"sourceCodeEnd":288,"githubUrl":"https://github.com/apache/maven/blob/e4093d4e120eac99d6bdce5ba67cace2f3085c97/impl/maven-impl/src/main/java/org/apache/maven/impl/AbstractSession.java#L252-L288","documentation":"AbstractSession.getArtifact(Class, artifact) is a closed dispatch: it only accepts exactly Artifact.class, DownloadedArtifact.class or ProducedArtifact.class. Any other Class object (including subclasses of these three, or unrelated classes) falls through the if-chain and throws IllegalArgumentException. This is an API-misuse guard for the Maven 4 consumer API's artifact cache.","triggerScenarios":"Calling session.getArtifact(SomeSubclassOfArtifact.class, artifact), session.getArtifact(null, artifact) with a non-null check bypassed, or passing e.g. ArtifactCoordinates.class / a custom Artifact implementation class as the first argument.","commonSituations":"Writing generic utility code that passes a Class<? extends Artifact> variable captured from generics, so the compiler cannot force one of the three supported literals; migrating from an older internal API that accepted arbitrary artifact types.","solutions":["Pass one of the exact literals: Artifact.class, DownloadedArtifact.class or ProducedArtifact.class","If you hold a Class<? extends Artifact> from generic code, switch on it explicitly and reject unknown values early with your own error message","Do not subclass the API artifact types expecting getArtifact to instantiate them"],"exampleFix":"// before\n<T extends Artifact> T get(Session s, Class<T> clazz, org.eclipse.aether.artifact.Artifact a) {\n    return s.getArtifact(clazz, a); // throws for subclasses\n}\n\n// after\n<T extends Artifact> T get(Session s, Class<T> clazz, org.eclipse.aether.artifact.Artifact a) {\n    if (clazz != Artifact.class && clazz != DownloadedArtifact.class && clazz != ProducedArtifact.class) {\n        throw new IllegalArgumentException('Use Artifact, DownloadedArtifact or ProducedArtifact, got ' + clazz);\n    }\n    return s.getArtifact(clazz, a);\n}","handlingStrategy":"type-guard","validationCode":"private static boolean isSupportedArtifactClass(Class<?> clazz) {\n    return clazz == Artifact.class || clazz == DownloadedArtifact.class || clazz == ProducedArtifact.class;\n}","typeGuard":"static boolean isSupportedArtifactClass(Class<? extends Artifact> clazz) {\n    return clazz == Artifact.class || clazz == DownloadedArtifact.class || clazz == ProducedArtifact.class;\n}","tryCatchPattern":null,"preventionTips":["Pass only the three exact literals; do not pass captured generic Class variables unchecked","Do not subclass API artifact types expecting getArtifact to instantiate them","Switch on the class explicitly at your API boundary and reject the rest early"],"tags":["maven","maven-api","validation","programming-error"],"backgroundTag":"unsupported-type","analyzedSha":"e4093d4e120eac99d6bdce5ba67cace2f3085c97","analyzedAt":"2026-08-21T22:58:24.034Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}