{"record":{"id":"f9d5561770793456","repo":"apache/maven","slug":"cannot-read-metadata-from-f9d556","errorCode":null,"errorMessage":"Cannot read metadata from '{}': {}","messagePattern":"Cannot read metadata from '(.+?)': (.+?)","errorType":"exception","errorClass":"RepositoryMetadataReadException","httpStatus":null,"severity":"error","filePath":"compat/maven-compat/src/main/java/org/apache/maven/artifact/repository/metadata/DefaultRepositoryMetadataManager.java","lineNumber":280,"sourceCode":"            } else {\n                repoMetadata.setMetadata(metadata);\n                setRepository = true;\n            }\n        }\n        return setRepository;\n    }\n\n    /*\n     * TODO share with DefaultPluginMappingManager.\n     */\n    protected Metadata readMetadata(File mappingFile) throws RepositoryMetadataReadException {\n\n        try (InputStream in = Files.newInputStream(mappingFile.toPath())) {\n            return new Metadata(new MetadataStaxReader().read(in, false));\n        } catch (FileNotFoundException e) {\n            throw new RepositoryMetadataReadException(\"Cannot read metadata from '\" + mappingFile + \"'\", e);\n        } catch (IOException | XMLStreamException e) {\n            throw new RepositoryMetadataReadException(\n                    \"Cannot read metadata from '\" + mappingFile + \"': \" + e.getMessage(), e);\n        }\n    }\n\n    /**\n     * Ensures the last updated timestamp of the specified metadata does not refer to the future and fixes the local\n     * metadata if necessary to allow proper merging/updating of metadata during deployment.\n     */\n    private void fixTimestamp(File metadataFile, Metadata metadata, Metadata reference) {\n        boolean changed = false;\n\n        if (metadata != null && reference != null) {\n            Versioning versioning = metadata.getVersioning();\n            Versioning versioningRef = reference.getVersioning();\n            if (versioning != null && versioningRef != null) {\n                String lastUpdated = versioning.getLastUpdated();\n                String now = versioningRef.getLastUpdated();\n                if (lastUpdated != null && now != null && now.compareTo(lastUpdated) < 0) {","sourceCodeStart":262,"sourceCodeEnd":298,"githubUrl":"https://github.com/apache/maven/blob/e4093d4e120eac99d6bdce5ba67cace2f3085c97/compat/maven-compat/src/main/java/org/apache/maven/artifact/repository/metadata/DefaultRepositoryMetadataManager.java#L262-L298","documentation":"DefaultRepositoryMetadataManager.readMetadata() opens a maven-metadata.xml file with Files.newInputStream and parses it with a StAX reader; any IOException (permissions, truncated file, disk error) or XMLStreamException (malformed XML) is wrapped in RepositoryMetadataReadException with this message. The placeholders are the metadata file path and the underlying parser/IO message. A missing file is tolerated by callers, so this specifically means the file exists but cannot be read or parsed.","triggerScenarios":"Any metadata-consuming path that calls readMetadata(): resolveAlways(), deploy()'s retrieval of previous metadata, or snapshot/version metadata merging, when the local maven-metadata.xml is hand-edited into invalid XML, truncated by a killed build, zero bytes, an HTML error page cached by a mirror, or unreadable due to permissions or file locking.","commonSituations":"A build killed (Ctrl-C, CI timeout) while maven-metadata.xml is being written; a repository proxy returning an HTML 500 page that gets saved as metadata; antivirus or a read-only ~/.m2/repository; CI jobs caching a corrupt local repository between runs.","solutions":["Delete the metadata file named in the message and rebuild with -U so Maven re-downloads it: rm ~/.m2/repository/<group>/<artifact>/maven-metadata*.xml","Inspect the first lines of that file (head) for an HTML error page or truncated XML; if it came from a remote repository, purge that metadata on the repository manager too","If the message is a permission or IO error, fix ownership/permissions on the local repository (chown -R) and check disk space","If a CI cache ships the local repository, invalidate the cache after repairing so the corrupt file does not come back"],"exampleFix":"# before: corrupt file left in place, build fails on every run\nhead -3 ~/.m2/repository/com/example/art/maven-metadata.xml   # shows HTML or truncated XML\nmvn clean install\n# after: remove the corrupt metadata and force a refresh\nrm ~/.m2/repository/com/example/art/maven-metadata*.xml\nmvn -U clean install","handlingStrategy":"try-catch","validationCode":"File f = new File(localRepository.getBasedir(),\n        localRepository.pathOfLocalRepositoryMetadata(metadata, remoteRepository));\nif (f.isFile()) {\n    try {\n        javax.xml.parsers.DocumentBuilderFactory.newInstance()\n                .newDocumentBuilder().parse(f); // fails fast on corrupt XML\n    } catch (Exception e) {\n        // delete/repair the metadata file before resolving\n    }\n}","typeGuard":null,"tryCatchPattern":"Catch RepositoryMetadataReadException around resolve()/resolveAlways()/deploy() call sites; treat it as a local-cache defect: delete the file named in the message and retry once, rethrow if it persists.","preventionTips":["Never hand-edit maven-metadata.xml files; let Maven write them.","Exclude maven-metadata*.xml from CI caches of the local repository, or validate cached repositories before reuse.","After killing a build, delete partially written maven-metadata.xml files before the next run.","Keep the local repository writable and not locked/scanned by antivirus."],"tags":["maven","metadata","xml","parsing","local-repository"],"backgroundTag":"corrupt-metadata-xml","analyzedSha":"e4093d4e120eac99d6bdce5ba67cace2f3085c97","analyzedAt":"2026-08-21T22:58:24.034Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}