{"record":{"id":"bb07391180b2d599","repo":"lingochamp/FileDownloader","slug":"can-t-create-the-block-complete-message-for-id-d","errorCode":null,"errorMessage":"can't create the block complete message for id[%d], status[%d]","messagePattern":"can't create the block complete message for id\\[(.+?)\\], status\\[(.+?)\\]","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"library/src/main/java/com/liulishuo/filedownloader/message/BlockCompleteMessage.java","lineNumber":39,"sourceCode":"\n/**\n * The interface of block complete message.\n *\n * @see SmallMessageSnapshot\n * @see LargeMessageSnapshot\n */\n\npublic interface BlockCompleteMessage {\n\n    MessageSnapshot transmitToCompleted();\n\n    class BlockCompleteMessageImpl extends MessageSnapshot implements BlockCompleteMessage {\n        private final MessageSnapshot mCompletedSnapshot;\n\n        public BlockCompleteMessageImpl(MessageSnapshot snapshot) {\n            super(snapshot.getId());\n            if (snapshot.getStatus() != FileDownloadStatus.completed) {\n                throw new IllegalArgumentException(FileDownloadUtils.formatString(\n                        \"can't create the block complete message for id[%d], status[%d]\",\n                        snapshot.getId(), snapshot.getStatus()));\n            }\n            this.mCompletedSnapshot = snapshot;\n        }\n\n        @Override\n        public MessageSnapshot transmitToCompleted() {\n            return this.mCompletedSnapshot;\n        }\n\n        @Override\n        public byte getStatus() {\n            return FileDownloadStatus.blockComplete;\n        }\n    }\n\n}","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/lingochamp/FileDownloader/blob/6237a8cac174bcc916e4342b14ab1ab72a5768d4/library/src/main/java/com/liulishuo/filedownloader/message/BlockCompleteMessage.java#L21-L57","documentation":"FileDownloader throws this IllegalArgumentException from the BlockCompleteMessageImpl constructor when the snapshot passed in is not in the 'completed' status. A block-complete message can only be built from a completed snapshot, since it wraps the completed snapshot to later transmit it; the constructor fails fast on any other status (pending, progress, error, warn, etc.).","triggerScenarios":"Calling new BlockCompleteMessage.BlockCompleteMessageImpl(snapshot) with a snapshot whose getStatus() != FileDownloadStatus.completed — e.g. wrapping a progress or error snapshot instead of the completed one.","commonSituations":"Custom code or patched library code that intercepts download lifecycle messages and manually constructs a block-complete message from the wrong snapshot; internal callers receiving a snapshot of an unexpected status from a custom MessageStation/Service layer.","solutions":["Check the snapshot status with snapshot.getStatus() and only construct BlockCompleteMessageImpl when it equals FileDownloadStatus.completed","Log snapshot.getStatus() and getId() at the call site to find where the wrong snapshot is being passed","Ensure the completed snapshot is delivered before the block-complete flow is triggered (do not pre-construct with a progress snapshot)","Update the library: newer versions of FileDownloader handle block-complete conversion internally without exposing this path"],"exampleFix":"// before\nBlockCompleteMessage msg = new BlockCompleteMessage.BlockCompleteMessageImpl(anySnapshot);\n// after\nif (anySnapshot.getStatus() == FileDownloadStatus.completed) {\n    BlockCompleteMessage msg = new BlockCompleteMessage.BlockCompleteMessageImpl(anySnapshot);\n}","handlingStrategy":"validation","validationCode":"if (snapshot != null && snapshot.getStatus() != FileDownloadStatus.completed) {\n    throw new IllegalStateException(\"BlockCompleteMessage requires a completed snapshot, got status=\" + snapshot.getStatus());\n}","typeGuard":"boolean isCompletedSnapshot(MessageSnapshot s) {\n    return s != null && s.getStatus() == FileDownloadStatus.completed;\n}","tryCatchPattern":"try {\n    BlockCompleteMessage msg = new BlockCompleteMessage.BlockCompleteMessageImpl(snapshot);\n} catch (IllegalArgumentException e) {\n    Log.e(TAG, \"Cannot build block complete message: \" + e.getMessage());\n}","preventionTips":["Always verify getStatus() == FileDownloadStatus.completed before constructing a block-complete message","Never wrap progress/error/warn snapshots in BlockCompleteMessageImpl","Let the library create block-complete messages internally instead of doing it manually","Log snapshot id and status when intercepting lifecycle messages"],"tags":["android","filedownloader","illegal-argument","status-mismatch"],"backgroundTag":"invalid-argument-value","analyzedSha":"6237a8cac174bcc916e4342b14ab1ab72a5768d4","analyzedAt":"2026-09-08T23:50:48.168Z","contentChangedAt":"2026-09-08T23:50:48.168Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}