{"record":{"id":"59512634e63c4e54","repo":"pxb1988/dex2jar","slug":"fail-to-assemble-file","errorCode":null,"errorMessage":"Fail to assemble ${file}","messagePattern":"Fail to assemble (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"d2j-jasmin/src/main/java/com/googlecode/d2j/jasmin/Jasmins.java","lineNumber":35,"sourceCode":"package com.googlecode.d2j.jasmin;\r\n\r\nimport org.antlr.runtime.ANTLRReaderStream;\r\nimport org.antlr.runtime.ANTLRStringStream;\r\nimport org.antlr.runtime.CommonTokenStream;\r\nimport org.antlr.runtime.RecognitionException;\r\nimport org.objectweb.asm.tree.ClassNode;\r\n\r\nimport java.io.*;\r\nimport java.nio.charset.StandardCharsets;\r\nimport java.nio.file.Files;\r\nimport java.nio.file.Path;\r\n\r\npublic class Jasmins {\r\n    public static ClassNode parse(Path file) throws IOException {\r\n        try (BufferedReader bufferedReader = Files.newBufferedReader(file, StandardCharsets.UTF_8)) {\r\n            return parse(file.toString(), bufferedReader);\r\n        } catch (RecognitionException e) {\r\n            throw new RuntimeException(\"Fail to assemble \" + file, e);\r\n        }\r\n    }\r\n\r\n    public static ClassNode parse(String fileName, Reader bufferedReader) throws IOException, RecognitionException {\r\n        ANTLRStringStream is = new ANTLRReaderStream(bufferedReader);\r\n        is.name = fileName;\r\n        JasminLexer lexer = new JasminLexer(is);\r\n        CommonTokenStream ts = new CommonTokenStream(lexer);\r\n        JasminParser parser = new JasminParser(ts);\r\n        return parser.parse();\r\n    }\r\n\r\n    public static ClassNode parse(String fileName, InputStream is) throws IOException, RecognitionException {\r\n        return parse(fileName, new InputStreamReader(is, StandardCharsets.UTF_8));\r\n    }\r\n}\r\n","sourceCodeStart":17,"sourceCodeEnd":52,"githubUrl":"https://github.com/pxb1988/dex2jar/blob/b5bda4fb4935ae8b3869b422454ae3b3896c7bc1/d2j-jasmin/src/main/java/com/googlecode/d2j/jasmin/Jasmins.java#L17-L52","documentation":"Jasmins.parse(Path) reads a Jasmin assembly (.j) file and feeds it to the ANTLR-based parser. If the parser raises a RecognitionException (invalid Jasmin syntax), parse wraps it in a RuntimeException with the message 'Fail to assemble <file>' and the original exception as cause. This converts a parser error into an unchecked exception that propagates up through Jasmin2JarCmd.","triggerScenarios":"Calling Jasmins.parse(file) on a .j file containing malformed Jasmin directives, bad instruction mnemonics, or wrong operand syntax that ANTLR cannot recognize; also invoked indirectly when d2j-jasmin2jar processes a directory containing an invalid .j file.","commonSituations":"Hand-written Jasmin files with typos, files generated for a different assembler syntax, corrupted/renamed non-Jasmin files given a .j extension, or Jasmin grammar differences from the version of dex2jar being used.","solutions":["Read the cause (RecognitionException) stack trace for the exact line/column of the syntax error.","Fix the Jasmin source at the reported line (mnemonic, directive, or operand issue).","Verify the file is genuine Jasmin assembly and not a class/dex/jar renamed to .j.","Compare syntax against a known-good .j sample for the dex2jar version in use.","If needed, catch RuntimeException around Jasmins.parse and report/skip the offending file."],"exampleFix":"// before\nireturn 0   // ireturn takes no operand -> RecognitionException\n\n// after\niconst_0\nireturn","handlingStrategy":"try-catch","validationCode":"// Basic sanity check before parsing\nif (!file.toString().endsWith(\".j\") || Files.size(file) == 0) {\n    throw new IllegalArgumentException(\"Not a plausible Jasmin source: \" + file);\n}","typeGuard":null,"tryCatchPattern":"try {\n    ClassNode cn = Jasmins.parse(file);\n} catch (RuntimeException e) {\n    Throwable cause = e.getCause(); // RecognitionException with line/column\n    System.err.println(\"Syntax error in \" + file + \": \" + cause.getMessage());\n}","preventionTips":["Lint Jasmin sources against the grammar for your dex2jar version before batch conversion.","Keep the RecognitionException cause for precise line/column diagnostics.","Ensure .j files are genuine Jasmin assembly, not renamed binaries.","Test hand-written assembly against a known-good sample first."],"tags":["jasmin","parser","assembly","syntax"],"backgroundTag":"invalid-argument-format","analyzedSha":"b5bda4fb4935ae8b3869b422454ae3b3896c7bc1","analyzedAt":"2026-09-08T00:44:01.258Z","contentChangedAt":"2026-09-08T00:44:01.258Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}