{"record":{"id":"16f0ae410097590e","repo":"apache/maven","slug":"cannot-change-the-version-information-for-an-attac","errorCode":null,"errorMessage":"Cannot change the version information for an attached artifact. It is derived from the main artifact.","messagePattern":"Cannot change the version information for an attached artifact\\. It is derived from the main artifact\\.","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"impl/maven-core/src/main/java/org/apache/maven/project/artifact/AttachedArtifact.java","lineNumber":86,"sourceCode":"\n    public AttachedArtifact(Artifact parent, String type, ArtifactHandler artifactHandler) {\n        this(parent, type, null, artifactHandler);\n    }\n\n    @Override\n    public void setArtifactId(String artifactId) {\n        throw new UnsupportedOperationException(\n                \"Cannot change the artifactId for an attached artifact.\" + \" It is derived from the main artifact.\");\n    }\n\n    @Override\n    public List<ArtifactVersion> getAvailableVersions() {\n        return parent.getAvailableVersions();\n    }\n\n    @Override\n    public void setAvailableVersions(List<ArtifactVersion> availableVersions) {\n        throw new UnsupportedOperationException(\"Cannot change the version information for an attached artifact.\"\n                + \" It is derived from the main artifact.\");\n    }\n\n    @Override\n    public String getBaseVersion() {\n        return parent.getBaseVersion();\n    }\n\n    @Override\n    public void setBaseVersion(String baseVersion) {\n        throw new UnsupportedOperationException(\"Cannot change the version information for an attached artifact.\"\n                + \" It is derived from the main artifact.\");\n    }\n\n    @Override\n    public String getDownloadUrl() {\n        return parent.getDownloadUrl();\n    }","sourceCodeStart":68,"sourceCodeEnd":104,"githubUrl":"https://github.com/apache/maven/blob/e4093d4e120eac99d6bdce5ba67cace2f3085c97/impl/maven-core/src/main/java/org/apache/maven/project/artifact/AttachedArtifact.java#L68-L104","documentation":"AttachedArtifact delegates available-version metadata to its parent: getAvailableVersions() returns the main artifact's list, while setAvailableVersions throws UnsupportedOperationException because that metadata is owned by the main artifact.","triggerScenarios":"Calling setAvailableVersions(list) on an AttachedArtifact, e.g. resolution or version-metadata code that stamps available versions onto every artifact of a project.","commonSituations":"Version-range tooling or resolvers iterating project.getAttachedArtifacts() and normalizing metadata on each entry; code ported from DefaultArtifact-based flows where the setter worked.","solutions":["Set available versions on the main artifact (project.getArtifact().setAvailableVersions(...)) and let attachments inherit it","Use a standalone DefaultArtifact for artifacts that need independent metadata","Skip attached artifacts when stamping metadata"],"exampleFix":"// before\nfor (Artifact a : project.getAttachedArtifacts()) {\n    a.setAvailableVersions(versions);\n}\n\n// after\nproject.getArtifact().setAvailableVersions(versions);","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"static boolean isAttachedArtifact(Artifact a) {\n    return a instanceof org.apache.maven.project.artifact.AttachedArtifact;\n}","tryCatchPattern":"if (isAttachedArtifact(artifact)) {\n    project.getArtifact().setAvailableVersions(versions); // metadata is owned by the main artifact\n} else {\n    artifact.setAvailableVersions(versions);\n}","preventionTips":["Apply version-metadata updates to the main artifact once, not per attached artifact","Skip attached artifacts in generic normalization passes"],"tags":["maven","artifact","attached-artifact","immutable","version-metadata"],"backgroundTag":"immutable-object-mutation","analyzedSha":"e4093d4e120eac99d6bdce5ba67cace2f3085c97","analyzedAt":"2026-08-21T22:58:24.034Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}