lingochamp/FileDownloader · error · NoFieldException

getEtag

Error message

getEtag

What it means

MessageSnapshot's base getEtag() throws NoFieldException because this snapshot type carries no ETag field. Only connected-status snapshots (which hold the HTTP ETag from the server response) override getEtag(); calling it on any other snapshot type is invalid.

Solutions

  1. Call getEtag() only when getStatus() == FileDownloadStatus.connected
  2. Retrieve the ETag from the HTTP layer or task data you control instead of the snapshot
  3. Catch IllegalStateException around the accessor when processing snapshots generically
  4. If ETag persistence matters, record it in your own storage at the connected callback point

Example fix

// before
String etag = snapshot.getEtag();
// after
String etag = snapshot.getStatus() == FileDownloadStatus.connected ? snapshot.getEtag() : null;
Defensive patterns

Strategy: validation

Validate before calling

if (snapshot.getStatus() != FileDownloadStatus.connected) {
    return null; // no ETag field on this snapshot
}

Type guard

String safeGetEtag(IMessageSnapshot s) {
    if (s.getStatus() != FileDownloadStatus.connected) return null;
    try { return s.getEtag(); } catch (IllegalStateException e) { return null; }
}

Try / catch

try {
    String etag = snapshot.getEtag();
} catch (IllegalStateException e) {
    // snapshot has no etag field for this status
}

Prevention

When it happens

Trigger: Calling IMessageSnapshot.getEtag() on a MessageSnapshot whose class is not a ConnectedMessageSnapshot — e.g. pending, progress, or error snapshots. Triggered through update/handoverMessage message inspection or direct snapshot probing.

Common situations: Breakpoint-resume logic that wants the server ETag from every lifecycle message; code caching ETags without filtering for the connected status; version mismatches where the callback contract changed.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of lingochamp/FileDownloader@6237a8cac1 (2026-09-08). Data as JSON: /api/errors/3b19f0eb0f727331. Report an issue: GitHub.

Appendix: source

Thrown at library/src/main/java/com/liulishuo/filedownloader/message/MessageSnapshot.java:58

    @Override
    public Throwable getThrowable() {
        throw new NoFieldException("getThrowable", this);
    }

    @Override
    public int getRetryingTimes() {
        throw new NoFieldException("getRetryingTimes", this);
    }

    @Override
    public boolean isResuming() {
        throw new NoFieldException("isResuming", this);
    }

    @Override
    public String getEtag() {
        throw new NoFieldException("getEtag", this);
    }

    @Override
    public long getLargeSofarBytes() {
        throw new NoFieldException("getLargeSofarBytes", this);
    }

    @Override
    public long getLargeTotalBytes() {
        throw new NoFieldException("getLargeTotalBytes", this);
    }

    @Override
    public int getSmallSofarBytes() {
        throw new NoFieldException("getSmallSofarBytes", this);
    }

    @Override

View on GitHub (pinned to 6237a8cac1)