{"record":{"id":"71f09241af2ba862","repo":"lingochamp/FileDownloader","slug":"getthrowable","errorCode":null,"errorMessage":"getThrowable","messagePattern":"getThrowable","errorType":"exception","errorClass":"NoFieldException","httpStatus":null,"severity":"error","filePath":"library/src/main/java/com/liulishuo/filedownloader/message/MessageSnapshot.java","lineNumber":43,"sourceCode":"/**\n * The message snapshot.\n */\npublic abstract class MessageSnapshot implements IMessageSnapshot, Parcelable {\n    private final int id;\n    protected boolean isLargeFile;\n\n    MessageSnapshot(int id) {\n        this.id = id;\n    }\n\n    @Override\n    public int getId() {\n        return id;\n    }\n\n    @Override\n    public Throwable getThrowable() {\n        throw new NoFieldException(\"getThrowable\", this);\n    }\n\n    @Override\n    public int getRetryingTimes() {\n        throw new NoFieldException(\"getRetryingTimes\", this);\n    }\n\n    @Override\n    public boolean isResuming() {\n        throw new NoFieldException(\"isResuming\", this);\n    }\n\n    @Override\n    public String getEtag() {\n        throw new NoFieldException(\"getEtag\", this);\n    }\n\n    @Override","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/lingochamp/FileDownloader/blob/6237a8cac174bcc916e4342b14ab1ab72a5768d4/library/src/main/java/com/liulishuo/filedownloader/message/MessageSnapshot.java#L25-L61","documentation":"MessageSnapshot's base implementations throw NoFieldException (an IllegalStateException) from getThrowable() to signal that this particular snapshot type does not carry a 'throwable' field. Only error-status snapshots override getThrowable() with a real value; calling it on any other snapshot type is an invalid access.","triggerScenarios":"Calling IMessageSnapshot.getThrowable() on a MessageSnapshot whose concrete class does not override getThrowable() — e.g. a pending/progress/started/completed snapshot. Callers are the internal update and handoverMessage paths that inspect snapshots crossing process/service boundaries.","commonSituations":"A FileDownloaderListener / callback inspects the raw snapshot without first checking getStatus() == error; code written against a different FileDownloader version where the method always returned a value; process-restore (Parcel) produced a snapshot type that doesn't match the expected status.","solutions":["Only call getThrowable() after verifying getStatus() == FileDownloadStatus.error","Use the cause delivered through your FileDownloadListener callback (BaseDownloadTask.getCause / errorCallback) instead of probing the snapshot","If you must handle all snapshot types generically, catch IllegalStateException around the accessor","Update to a FileDownloader version where IMessageSnapshot exposes null-safe accessors"],"exampleFix":"// before\nThrowable t = snapshot.getThrowable();\n// after\nif (snapshot.getStatus() == FileDownloadStatus.error) {\n    Throwable t = snapshot.getThrowable();\n}","handlingStrategy":"validation","validationCode":"if (snapshot.getStatus() != FileDownloadStatus.error) {\n    return null; // no throwable on this snapshot\n}","typeGuard":"Throwable safeGetThrowable(IMessageSnapshot s) {\n    if (s.getStatus() != FileDownloadStatus.error) return null;\n    try { return s.getThrowable(); } catch (IllegalStateException e) { return null; }\n}","tryCatchPattern":"try {\n    Throwable t = snapshot.getThrowable();\n} catch (IllegalStateException e) {\n    // snapshot has no throwable field for this status\n}","preventionTips":["Check getStatus() == FileDownloadStatus.error before calling getThrowable()","Prefer listener callbacks that deliver the cause directly","Handle snapshots by status before accessing non-id/getStatus accessors","Catch IllegalStateException when writing generic snapshot-processing code"],"tags":["android","filedownloader","no-field","snapshot-accessor"],"backgroundTag":"unsupported-operation","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"}