TeamNewPipe/NewPipe · error · NoSuchElementException
expected {} found {}
Error message
expected {} found {} What it means
Mp4DashReader.readBox(expected) reads a box and compares its 4-byte type against the expected atom constant. If they differ it throws NoSuchElementException naming both expected and found atoms. This is a structural guard used during ftyp parsing and full-box reads where the next box must be a specific type; a mismatch means the file layout diverged from what the parser assumes.
Source
Thrown at app/src/main/java/org/schabi/newpipe/streams/Mp4DashReader.java:281
}
private Box readBox() throws IOException {
final Box b = new Box();
b.offset = stream.position();
b.size = stream.readUnsignedInt();
b.type = stream.readInt();
if (b.size == 1) {
b.size = stream.readLong();
}
return b;
}
private Box readBox(final int expected) throws IOException {
final Box b = readBox();
if (b.type != expected) {
throw new NoSuchElementException("expected " + boxName(expected)
+ " found " + boxName(b));
}
return b;
}
private byte[] readFullBox(final Box ref) throws IOException {
// full box reading is limited to 2 GiB, and should be enough
final int size = (int) ref.size;
final ByteBuffer buffer = ByteBuffer.allocate(size);
buffer.putInt(size);
buffer.putInt(ref.type);
final int read = size - 8;
if (stream.read(buffer.array(), 8, read) != read) {
throw new EOFException(String.format("EOF reached in box: type=%s offset=%s size=%s",
boxName(ref.type), ref.offset, ref.size));View on GitHub (pinned to 9e8be09156)
Solutions
- Re-download/re-mux; the box sequence does not match what this strict reader expects.
- Use a more tolerant MP4 inspector (mp4info/MP4Box) to identify which box is misplaced and re-emit the file correctly.
- If you only need specific boxes, use untilBox() (which skips unknown boxes) instead of readBox(expected).
- Catch NoSuchElementException at the parse boundary and report the structural mismatch.
Example fix
// before — strict read that fails on an unexpected leading box
Box b = readBox(ATOM_FTYP); // throws if a non-ftyp box leads
// after — skip until the expected box is found
Box b = untilBox(null, ATOM_FTYP);
if (b == null) throw new IOException("ftyp box missing entirely"); Defensive patterns
Strategy: try-catch
Validate before calling
// Prefer untilBox() to skip unknown boxes instead of readBox(expected).
// Before a strict read, scan forward to the expected box:
Box b = untilBox(parent, ATOM_FTYP);
if (b == null) throw new IOException("required box ftyp not present"); Type guard
// A box-type narrowing helper:
public static Box expectBox(Box b, int expected) throws NoSuchElementException {
if (b.type != expected)
throw new NoSuchElementException("expected "+boxName(expected)+" found "+boxName(b));
return b;
} Try / catch
try {
Box b = readBox(ATOM_FTYP);
} catch (NoSuchElementException e) {
if (e.getMessage().startsWith("expected")) {
// unexpected leading box — try skipping one box and retry, or reject the file
Log.w(TAG, "box order unexpected: " + e.getMessage());
} else throw e;
} Prevention
- Use untilBox() for tolerant scanning; reserve readBox(expected) for invariants.
- Re-mux non-conformant files with ffmpeg/MP4Box.
- Validate box order with mp4info before strict parsing.
- Do not assume a specific box leads the file without sniffing.
When it happens
Trigger: Calling readBox(expected) when the stream position points at a different box type than anticipated — e.g. expecting ATOM_FTYP but finding another atom, or any ordered-box-read where the next box is not the assumed type. Happens when a box is unexpectedly absent/extra/reordered.
Common situations: A non-conformant MP4 where boxes are in an unusual order; an extra metadata box inserted by a tagging tool before ftyp; a truncated file whose remaining bytes decode to an unexpected atom type; an encrypted/DRM'd file with altered structure.
Related errors
- Not a MPEG-4 DASH container, major brand is not 'dash' or 'i
- The provided Mp4 doesn't have the 'moov' box
- moof found without mdat
- mdat found without moof
- EOF reached in box: type=%s offset=%s size=%s
AI-assisted analysis of TeamNewPipe/NewPipe@9e8be09156 (2026-08-14).
Data as JSON: /api/errors/84e076c17070e0e7.
Report an issue: GitHub.