{"record":{"id":"25da3ac8c6a5fa2e","repo":"aeron-io/aeron","slug":"negative-position-encoded-in-the-file-name-filename","errorCode":null,"errorMessage":"negative position encoded in the file name: \" + filename","messagePattern":"negative position encoded in the file name: \" \\+ filename","errorType":"exception","errorClass":"ArchiveException","httpStatus":null,"severity":"error","filePath":"aeron-archive/src/main/java/io/aeron/archive/Catalog.java","lineNumber":1178,"sourceCode":"                    }\n                }\n            }\n        }\n\n        return index;\n    }\n\n    static String findSegmentFileWithHighestPosition(final List<String> segmentFiles)\n    {\n        long maxSegmentPosition = NULL_POSITION;\n        String maxFileName = null;\n\n        for (final String filename : segmentFiles)\n        {\n            final long filePosition = parseSegmentFilePosition(filename);\n            if (filePosition < 0)\n            {\n                throw new ArchiveException(\"negative position encoded in the file name: \" + filename);\n            }\n\n            if (filePosition > maxSegmentPosition)\n            {\n                maxSegmentPosition = filePosition;\n                maxFileName = filename;\n            }\n        }\n\n        return maxFileName;\n    }\n\n    static long parseSegmentFilePosition(final String filename)\n    {\n        final int dashOffset = filename.indexOf('-');\n        if (-1 == dashOffset)\n        {\n            throw new ArchiveException(\"invalid filename format: \" + filename);","sourceCodeStart":1160,"sourceCodeEnd":1196,"githubUrl":"https://github.com/aeron-io/aeron/blob/6d60124e15e35c11b49ba2e3c2c2858a09a18803/aeron-archive/src/main/java/io/aeron/archive/Catalog.java#L1160-L1196","documentation":"Thrown by Catalog when determining the last recorded position of a recording from its segment files: a segment file name encodes its starting position, and a parsed position that is negative is invalid. This indicates a malformed or corrupted segment file name in the archive directory, so the catalog cannot compute the recording's max position safely.","triggerScenarios":"Scanning a recording's segment files (Catalog.scanLastFile / during replay/extend) where a file's name does not match the expected <recordingId>-<position>.rec pattern with a valid numeric position — parseSegmentFilePosition returns negative for unparseable or negative-encoded names.","commonSituations":"Manually renamed or partially written segment files; files created by a different/older Aeron version with a different naming scheme; stray files matching the glob (editor backups like 'foo.rec~', temp files) dropped into the archive directory; corrupted filenames after filesystem issues.","solutions":["Inspect the archive directory and remove or rename the malformed segment file so only valid <recordingId>-<position>.rec files remain","Run ArchiveTool verify on the archive directory to identify and fix inconsistent files","Restore affected segment files from a clean backup with canonical names","Check for backup/temp files (e.g. cp/mv artifacts) in the archive dir and move them out"],"exampleFix":"// before\nmv archive/1000-4607182418800017413.rec archive/1000-rec.rec  // corrupts name-encoded position\n// after\nmv archive/1000-rec.rec archive/1000-4607182418800017413.rec  // restore canonical <recordingId>-<position>.rec","handlingStrategy":"try-catch","validationCode":"import java.io.File;\nimport java.util.regex.Pattern;\n\nprivate static final Pattern SEGMENT = Pattern.compile(\"^(\\\\d+)-(\\\\d+)(\\\\.rec)?$\");\n\nstatic boolean hasValidSegmentNames(File archiveDir, long recordingId) {\n    File[] files = archiveDir.listFiles((d, n) -> n.startsWith(recordingId + \"-\"));\n    if (files == null) return true;\n    for (File f : files) {\n        java.util.regex.Matcher m = SEGMENT.matcher(f.getName());\n        if (!m.matches() || Long.parseLong(m.group(2)) < 0) return false;\n    }\n    return true;\n}","typeGuard":null,"tryCatchPattern":"try {\n    aeronArchive.extendRecording(...);\n} catch (ArchiveException e) {\n    if (e.getMessage().startsWith(\"negative position encoded in the file name\")) {\n        // quarantine/remove the malformed segment file, run ArchiveTool verify, retry\n    } else {\n        throw e;\n    }\n}","preventionTips":["Never rename files inside the archive directory","Exclude backup/temp artifacts (e.g. ~ files) from the archive dir","Copy archives with tools that preserve exact file names","Run ArchiveTool verify after any manual intervention or crash"],"tags":["aeron-archive","segment-file-naming","corruption"],"backgroundTag":"invalid-identifier-format","analyzedSha":"6d60124e15e35c11b49ba2e3c2c2858a09a18803","analyzedAt":"2026-09-12T11:17:07.683Z","contentChangedAt":"2026-09-12T11:17:07.683Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}