apache / apache/maven-resolver

[MRESOLVER-597] RepositorySystem.resolveArtifactRepositorySystemSession session, ArtifactRequest request) throws unexpected IllegalArgumentException

Open
#1,269 1 comment 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Java
Stars
152
Forks
160
Avg merge
1d 4h
Merged PRs (30d)
49

Description

**[Konrad Windszus](https://issues.apache.org/jira/secure/ViewProfile.jspa?name=kwin)** opened **[MRESOLVER-597](https://issues.apache.org/jira/browse/MRESOLVER-597?redirect=false)** and commented

I see the following exception when trying to resolve an artifact which does not have a version via

```
ArtifactRequest request = new ArtifactRequest();
request.setArtifact(artifact);
ArtifactResult result = repositorySystem.resolveArtifact(repositorySession, request);
```

```
java.lang.IllegalArgumentException: version can neither be null, empty nor blank
at org.apache.maven.artifact.ArtifactUtils.notBlank (ArtifactUtils.java:95)
at org.apache.maven.artifact.ArtifactUtils.key (ArtifactUtils.java:86)
at org.apache.maven.ReactorReader.findArtifact (ReactorReader.java:96)
at org.eclipse.aether.internal.impl.DefaultArtifactResolver.resolve (DefaultArtifactResolver.java:350)
at org.eclipse.aether.internal.impl.DefaultArtifactResolver.resolveArtifacts (DefaultArtifactResolver.java:261)
at org.eclipse.aether.internal.impl.DefaultArtifactResolver.resolveArtifact (DefaultArtifactResolver.java:243)
at org.eclipse.aether.internal.impl.DefaultRepositorySystem.resolveArtifact (DefaultRepositorySystem.java:278)
```

According to https://github.com/apache/maven-resolver/blob/362a43675f01b8bb3d85d7b0ff76a21d57de6fee/maven-resolver-api/src/main/java/org/eclipse/aether/artifact/DefaultArtifact.java#L137 every argument passed to the constructor of `DefaultArtifact` may be `null` or empty. However not all `Artifact` objects are valid then for `ArtifactRequest`.

Although throwing an exception is totally valid here either the `IllegalArgumentException` should be documented in the javadoc of https://maven.apache.org/resolver/apidocs/org/eclipse/aether/RepositorySystem.html#resolveArtifact(org.eclipse.aether.RepositorySystemSession,org.eclipse.aether.resolution.ArtifactRequest).
IMHO it would make sense to throw the exception already when either populating or constructing the `ArtifactRequest`, as only non empty coordinates are supported.

---

**Affects:** 1.9.20

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with RepositorySystem.resolveArtifact and the linked DefaultArtifact constructor behavior, then reproduce the ArtifactRequest using an artifact without a version. Compare the alternatives raised in the issue—documenting the IllegalArgumentException or validating earlier—and define completion around a consistent, tested contract for invalid coordinates.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.