{"record":{"id":"4737348b742b0982","repo":"TeamNewPipe/NewPipe","slug":"expected-found-473734","errorCode":null,"errorMessage":"expected {} found {}","messagePattern":"expected (.+?) found (.+?)","errorType":"exception","errorClass":"NoSuchElementException","httpStatus":null,"severity":"error","filePath":"app/src/main/java/org/schabi/newpipe/streams/WebMReader.java","lineNumber":183,"sourceCode":"        }\n\n        throw new IOException(\"Invalid encoded length\");\n    }\n\n    private Element readElement() throws IOException {\n        final Element elem = new Element();\n        elem.offset = stream.position();\n        elem.type = (int) readEncodedNumber();\n        elem.contentSize = readEncodedNumber();\n        elem.size = elem.contentSize + stream.position() - elem.offset;\n\n        return elem;\n    }\n\n    private Element readElement(final int expected) throws IOException {\n        final Element elem = readElement();\n        if (expected != 0 && elem.type != expected) {\n            throw new NoSuchElementException(\"expected \" + elementID(expected)\n                    + \" found \" + elementID(elem.type));\n        }\n\n        return elem;\n    }\n\n    private Element untilElement(final Element ref, final int... expected) throws IOException {\n        Element elem;\n        while (ref == null ? stream.available() : (stream.position() < (ref.offset + ref.size))) {\n            elem = readElement();\n            if (expected.length < 1) {\n                return elem;\n            }\n            for (final int type : expected) {\n                if (elem.type == type) {\n                    return elem;\n                }\n            }","sourceCodeStart":165,"sourceCodeEnd":201,"githubUrl":"https://github.com/TeamNewPipe/NewPipe/blob/9e8be091560a69f35d44bd252eb00bc7911c977b/app/src/main/java/org/schabi/newpipe/streams/WebMReader.java#L165-L201","documentation":"WebMReader.readElement(expected) reads an EBML element and compares its type ID against the expected constant. If they differ (and expected != 0), NoSuchElementException 'expected X found Y' is thrown, naming both IDs in hex. This strict read is used where the next element must be a specific type; a mismatch means the element sequence diverged from expectations.","triggerScenarios":"Calling readElement(expected) when the stream is positioned at an element whose type is not the expected one — e.g. expecting ID_INFO but finding ID_TRACKS. Occurs when an element is unexpectedly absent/extra/reordered or the parser is desynchronized.","commonSituations":"A malformed WebM with elements out of order; the parser desynchronized after a corrupt element; a non-conformant muxer emitting unexpected elements; a truncated stream where bytes decode to a wrong element ID.","solutions":["Use untilElement(ref, expected...) which skips unknown elements instead of readElement(expected), matching the parser's own tolerant path.","Re-download the file; element-order corruption indicates a damaged transfer.","Re-mux with a conformant WebM muxer.","Validate the file with mkvinfo/ffprobe before parsing."],"exampleFix":"// before — strict read fails on unexpected leading element\nElement e = readElement(ID_SEGMENT); // throws if another element leads\n\n// after — skip to the expected element\nElement e = untilElement(null, ID_SEGMENT);\nif (e == null) throw new IOException(\"segment element missing\");","handlingStrategy":"try-catch","validationCode":"// Use untilElement(ref, expected...) which skips unknown elements instead of readElement(expected).\nElement e = untilElement(parent, ID_SEGMENT);\nif (e == null) throw new IOException(\"required Segment element missing\");","typeGuard":"public static boolean elementIsType(Element e, int expected) {\n    return e != null && e.type == expected;\n}","tryCatchPattern":"try {\n    Element e = readElement(ID_SEGMENT);\n} catch (NoSuchElementException ex) {\n    if (ex.getMessage().startsWith(\"expected\")) {\n        // unexpected element — skip forward or re-mux the file\n        Log.w(TAG, \"element order unexpected: \" + ex.getMessage());\n    } else throw ex;\n}","preventionTips":["Prefer untilElement() for tolerant scanning; use readElement(expected) only for invariants.","Re-mux non-conformant WebM with ffmpeg/ffmpeg -f webm.","Validate element order with mkvinfo before strict parsing.","Treat element-order errors as corruption indicators."],"tags":["webm","ebml","format-validation","container","java"],"backgroundTag":null,"analyzedSha":"9e8be091560a69f35d44bd252eb00bc7911c977b","analyzedAt":"2026-08-14T00:11:33.519Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}