{"record":{"id":"3d5b2749e7ccd700","repo":"Konloch/bytecode-viewer","slug":"unknown-opcode-encountered","errorCode":null,"errorMessage":"Unknown opcode encountered: ","messagePattern":"Unknown opcode encountered: ","errorType":"exception","errorClass":"UnexpectedException","httpStatus":null,"severity":"warning","filePath":"src/main/java/the/bytecode/club/bytecodeviewer/searching/RegexInsnFinder.java","lineNumber":160,"sourceCode":"        for (AbstractInsnNode ain : mn.instructions.toArray())\n            if (ain.getOpcode() >= 0)\n            {\n                il.add(ain);\n            }\n        AbstractInsnNode[] instructions = il.toArray(new AbstractInsnNode[0]);\n        offsets = new int[instructions.length];\n        StringBuilder insnStringBuilder = new StringBuilder();\n        for (int i = 0; i < instructions.length; i++)\n        {\n            offsets[i] = -1;\n            final AbstractInsnNode ain = instructions[i];\n            if (ain.getOpcode() >= 0)\n            {\n                if (ain.getOpcode() >= opcodes.length)\n                {\n                    try\n                    {\n                        throw new UnexpectedException(\"Unknown opcode encountered: \" + ain.getOpcode());\n                    }\n                    catch (UnexpectedException e)\n                    {\n                        BytecodeViewer.handleException(e);\n                    }\n                }\n                offsets[i] = insnStringBuilder.length();\n                insnStringBuilder.append(opcodes[ain.getOpcode()]);\n                insnStringBuilder = new StringBuilder(getInsString(ain));\n                insnStringBuilder.append(\" \");\n            }\n        }\n        insnString = insnStringBuilder.toString();\n    }\n\n    // Do a pattern check against each instruction directly,\n    // without building a string of the whole method.\n    public static boolean staticScan(ClassNode node, MethodNode mn, Pattern pattern)","sourceCodeStart":142,"sourceCodeEnd":178,"githubUrl":"https://github.com/Konloch/bytecode-viewer/blob/31430e0033fa220db566b5ef461256727ff6793b/src/main/java/the/bytecode/club/bytecodeviewer/searching/RegexInsnFinder.java#L142-L178","documentation":"RegexInsnFinder.refresh builds an opcode-to-string lookup and throws an UnexpectedException when an instruction's opcode is >= 0 but outside the opcodes array bounds. This means the method's instruction list contains an opcode the finder's table does not cover, typically after an ASM version mismatch or corrupted/unusual bytecode. The exception is caught and routed to BytecodeViewer.handleException, so it surfaces as an error dialog rather than crashing.","triggerScenarios":"Calling setMethod (which invokes refresh) on a MethodNode whose instructions contain an opcode >= opcodes.length — usually bytecode produced by a newer compiler/ASM version than the opcode table supports.","commonSituations":"Analyzing classes compiled with newer bytecode features after a library upgrade that changed opcode coverage; frameworks injecting exotic opcodes; a stale opcodes array after an ASM upgrade.","solutions":["Update BCV/ASM so the opcode table covers all opcodes in the analyzed class","Report the failing class to the BCV maintainers via handleException's dialog (this is flagged as an internal invariant break)","Check the reported opcode value and confirm whether the input class file is corrupt or from an unsupported version","Work around by excluding that class/method from regex instruction searching"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"for (AbstractInsnNode ain : method.instructions) {\n    int op = ain.getOpcode();\n    if (op >= knownOpcodeCount) throw new IllegalStateException(\"Unsupported opcode \" + op + \" before regex search\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    finder.setMethod(method);\n} catch (UnexpectedException e) {\n    BytecodeViewer.handleException(e); // or log opcode and skip this method\n}","preventionTips":["Keep BCV/ASM versions aligned with the bytecode versions you analyze","Validate input classes with ASM's CheckClassAdapter before searching","Skip classes compiled by newer JDKs until tooling is updated","Report unknown-opcode classes upstream with the logged opcode value"],"tags":["java","asm","bytecode","opcode"],"backgroundTag":"unknown-opcode","analyzedSha":"31430e0033fa220db566b5ef461256727ff6793b","analyzedAt":"2026-09-05T18:22:22.725Z","contentChangedAt":"2026-09-05T18:22:22.725Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}