{"record":{"id":"18da61cb71f80736","repo":"Konloch/bytecode-viewer","slug":"invalid-constant-pool","errorCode":null,"errorMessage":"Invalid constant pool","messagePattern":"Invalid constant pool","errorType":"exception","errorClass":"ClassFileFormatException","httpStatus":null,"severity":"error","filePath":"src/main/java/the/bytecode/club/bytecodeviewer/decompilers/jdgui/JDGUIClassFileUtil.java","lineNumber":71,"sourceCode":"            /* int minor_version = */\n            dis.readUnsignedShort();\n            /* int major_version = */\n            dis.readUnsignedShort();\n\n            Constant[] constants = DeserializeConstants(dis);\n\n            /* int access_flags = */\n            dis.readUnsignedShort();\n            int this_class = dis.readUnsignedShort();\n\n            if (this_class > constants.length)\n            {\n                throw new ClassFileFormatException(\"Unknown Java structure\");\n            }\n            Constant c = constants[this_class];\n            if ((c == null) || (c.getTag() != Constant.CONSTANT_Class))\n            {\n                throw new ClassFileFormatException(\"Invalid constant pool\");\n            }\n\n            c = constants[((ConstantClass) c).getNameIndex()];\n            if ((c == null) || (c.getTag() != Constant.CONSTANT_Utf8))\n            {\n                throw new ClassFileFormatException(\"Invalid constant pool\");\n            }\n\n            String internalClassName = ((ConstantUtf8) c).getValue();\n            String pathSuffix = internalClassName.replace(INTERNAL_PACKAGE_SEPARATOR, File.separatorChar) + CLASS_FILE_SUFFIX;\n\n            int index = pathToClass.indexOf(pathSuffix);\n\n            if (index < 0)\n            {\n                throw new ClassFileFormatException(\"Invalid internal class name\");\n            }\n","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/Konloch/bytecode-viewer/blob/31430e0033fa220db566b5ef461256727ff6793b/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/jdgui/JDGUIClassFileUtil.java#L53-L89","documentation":"The this_class constant-pool entry must be a CONSTANT_Class whose name_index points at a CONSTANT_Utf8 entry holding the internal class name. ExtractDirectoryPath throws ClassFileFormatException('Invalid constant pool') when the this_class entry is absent (long/double entries leave a hole) or its tag is not CONSTANT_Class. The constant pool does not match what the JVM spec requires for a valid class.","triggerScenarios":"ExtractDirectoryPath on a file whose this_class slot is empty (unusual) or whose resolved constant is not a CONSTANT_Class — i.e. malformed bytecode, a partially written class file, or a non-class binary that coincidentally passed the magic check.","commonSituations":"Corrupted class files after failed extraction/patching; class files assembled by custom bytecode generators with wrong cp_index wiring; aggressive obfuscators that break invariants this lightweight parser assumes; byte-edited binaries.","solutions":["Verify with a spec-compliant tool (javap -v, javac -Xlint, ASM CheckClassAdapter) that the constant pool is valid; recompile if it is not.","Re-extract the class from its original JAR/APK to rule out truncation/corruption during copying.","Remove or rerun any bytecode patching/obfuscation step that produced the malformed pool.","Catch ClassFileFormatException per-file and skip the offending class in batch decompilation."],"exampleFix":"// before\nString dir = JDGUIClassFileUtil.ExtractDirectoryPath(path);\n\n// after\ntry {\n    String dir = JDGUIClassFileUtil.ExtractDirectoryPath(path);\n} catch (org.jd.core.v1.service.deserializer.classfile.ClassFileFormatException e) {\n    if (\"Invalid constant pool\".equals(e.getMessage())) {\n        // skip malformed class\n    } else {\n        throw e;\n    }\n}","handlingStrategy":"try-catch","validationCode":"try (FileInputStream in = new FileInputStream(path)) {\n    ClassReader cr = new ClassReader(in); // ASM or similar spec-compliant parser\n    // constructor throws InvalidClassFormatException if the pool is broken\n}","typeGuard":null,"tryCatchPattern":"try {\n    String dir = JDGUIClassFileUtil.ExtractDirectoryPath(path);\n} catch (org.jd.core.v1.service.deserializer.classfile.ClassFileFormatException e) {\n    if (\"Invalid constant pool\".equals(e.getMessage())) {\n        logger.warn(\"Broken constant pool: {}\", path); // skip\n    } else {\n        throw e;\n    }\n}","preventionTips":["Verify bytecode with ASM's CheckClassAdapter or javap before feeding it to the lightweight parser.","After bytecode instrumentation, always re-run verification — broken cp_index wiring is the usual cause.","Avoid hand-editing class files; regenerate them instead.","Re-extract classes from the original JAR/APK if corruption is suspected.","Handle each file in its own try-catch during batch runs."],"tags":["java","class-format","constant-pool","decompiler"],"backgroundTag":"invalid-class-file-format","analyzedSha":"31430e0033fa220db566b5ef461256727ff6793b","analyzedAt":"2026-09-05T18:22:22.725Z","contentChangedAt":"2026-09-05T18:22:22.725Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}