{"record":{"id":"8aca67d68b03935d","repo":"antlr/antlr4","slug":"unexpected-data-entry","errorCode":null,"errorMessage":"Unexpected data entry","messagePattern":"Unexpected data entry","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"runtime/Java/src/org/antlr/v4/runtime/misc/InterpreterDataReader.java","lineNumber":66,"sourceCode":"\t * ...\n\t *\n\t * atn:\n\t * <a single line with comma separated int values> enclosed in a pair of squared brackets.\n\t *\n\t * Data for a parser does not contain channel and mode names.\n\t */\n\tpublic static InterpreterData parseFile(String fileName) {\n\t\tInterpreterData result = new InterpreterData();\n\t\tresult.ruleNames = new ArrayList<String>();\n\n\t\ttry (BufferedReader br = new BufferedReader(new FileReader(fileName))) {\n\t\t    String line;\n\t\t  \tList<String> literalNames = new ArrayList<String>();\n\t\t  \tList<String> symbolicNames = new ArrayList<String>();\n\n\t\t\tline = br.readLine();\n\t\t\tif ( !line.equals(\"token literal names:\") )\n\t\t\t\tthrow new RuntimeException(\"Unexpected data entry\");\n\t\t    while ((line = br.readLine()) != null) {\n\t\t       if ( line.isEmpty() )\n\t\t\t\t\tbreak;\n\t\t\t\tliteralNames.add(line.equals(\"null\") ? \"\" : line);\n\t\t    }\n\n\t\t\tline = br.readLine();\n\t\t\tif ( !line.equals(\"token symbolic names:\") )\n\t\t\t\tthrow new RuntimeException(\"Unexpected data entry\");\n\t\t    while ((line = br.readLine()) != null) {\n\t\t       if ( line.isEmpty() )\n\t\t\t\t\tbreak;\n\t\t\t\tsymbolicNames.add(line.equals(\"null\") ? \"\" : line);\n\t\t    }\n\n\t\t  \tresult.vocabulary = new VocabularyImpl(literalNames.toArray(new String[0]), symbolicNames.toArray(new String[0]));\n\n\t\t\tline = br.readLine();","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/antlr/antlr4/blob/7d5770395bb7b02eb56e7c62662cb1d7c08f42a3/runtime/Java/src/org/antlr/v4/runtime/misc/InterpreterDataReader.java#L48-L84","documentation":"InterpreterDataReader.parseFile reads the .interp file emitted by the ANTLR tool (via -atn/interp output) as a sequence of labeled sections. The very first line must be exactly 'token literal names:'. Anything else (BOM, wrong file, different section order, empty file) throws RuntimeException('Unexpected data entry').","triggerScenarios":"Passing a path that is not a .interp file (e.g. a .tokens, .java, or .g4 file), a file with a UTF-8 BOM or CRLF-prefixed first line, a file truncated to empty, or an .interp written by a tool version that emits a different first section.","commonSituations":"Wiring a ParserInterpreter/LexerInterpreter: new Grammar(fileName, tokens, rules, atn) built from InterpreterDataReader data but the wrong file path passed. Generating with an old/new ANTLR that changes the .interp layout. Files edited by hand or transferred with encoding conversion.","solutions":["Verify the file's first line is byte-exact 'token literal names:' with no BOM/whitespace (hexdump -C file | head)","Regenerate the .interp with the same ANTLR tool version as the runtime (antlr4 -Dlanguage=Java ... emits .interp alongside generated sources)","Point the reader at the correct file; .interp lives next to the generated Lexer/Parser .java files by default","If the file came through Windows tooling, strip CR characters and re-save as UTF-8 without BOM"],"exampleFix":"// before\nInterpreterData data = InterpreterDataReader.parseFile(\"MyLexer.tokens\"); // wrong file -> throws\n// after\nInterpreterData data = InterpreterDataReader.parseFile(\"MyLexer.interp\");","handlingStrategy":"validation","validationCode":"List<String> head = Files.readAllLines(Paths.get(path), StandardCharsets.UTF_8);\nif (head.isEmpty() || !\"token literal names:\".equals(head.get(0))) {\n    throw new IllegalArgumentException(\"not a valid .interp file: \" + path);\n}","typeGuard":null,"tryCatchPattern":"catch (RuntimeException e) { if (\"Unexpected data entry\".equals(e.getMessage())) { /* wrong or corrupt .interp: regenerate */ } else throw e; }","preventionTips":["Pass the .interp file, not .tokens or generated .java","Regenerate .interp whenever the tool version changes","Keep .interp files UTF-8 without BOM, LF or CR-stripped"],"tags":["antlr","java","interp","interpreter","file-format"],"backgroundTag":null,"analyzedSha":"7d5770395bb7b02eb56e7c62662cb1d7c08f42a3","analyzedAt":"2026-08-14T14:47:56.354Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}