Konloch/bytecode-viewer · error · ClassFileFormatException
Invalid constant pool
Error message
Invalid constant pool
What it means
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.
Source
Thrown at src/main/java/the/bytecode/club/bytecodeviewer/decompilers/jdgui/JDGUIClassFileUtil.java:71
/* int minor_version = */
dis.readUnsignedShort();
/* int major_version = */
dis.readUnsignedShort();
Constant[] constants = DeserializeConstants(dis);
/* int access_flags = */
dis.readUnsignedShort();
int this_class = dis.readUnsignedShort();
if (this_class > constants.length)
{
throw new ClassFileFormatException("Unknown Java structure");
}
Constant c = constants[this_class];
if ((c == null) || (c.getTag() != Constant.CONSTANT_Class))
{
throw new ClassFileFormatException("Invalid constant pool");
}
c = constants[((ConstantClass) c).getNameIndex()];
if ((c == null) || (c.getTag() != Constant.CONSTANT_Utf8))
{
throw new ClassFileFormatException("Invalid constant pool");
}
String internalClassName = ((ConstantUtf8) c).getValue();
String pathSuffix = internalClassName.replace(INTERNAL_PACKAGE_SEPARATOR, File.separatorChar) + CLASS_FILE_SUFFIX;
int index = pathToClass.indexOf(pathSuffix);
if (index < 0)
{
throw new ClassFileFormatException("Invalid internal class name");
}
View on GitHub (pinned to 31430e0033)
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.
Example fix
// before
String dir = JDGUIClassFileUtil.ExtractDirectoryPath(path);
// after
try {
String dir = JDGUIClassFileUtil.ExtractDirectoryPath(path);
} catch (org.jd.core.v1.service.deserializer.classfile.ClassFileFormatException e) {
if ("Invalid constant pool".equals(e.getMessage())) {
// skip malformed class
} else {
throw e;
}
} Defensive patterns
Strategy: try-catch
Validate before calling
try (FileInputStream in = new FileInputStream(path)) {
ClassReader cr = new ClassReader(in); // ASM or similar spec-compliant parser
// constructor throws InvalidClassFormatException if the pool is broken
} Try / catch
try {
String dir = JDGUIClassFileUtil.ExtractDirectoryPath(path);
} catch (org.jd.core.v1.service.deserializer.classfile.ClassFileFormatException e) {
if ("Invalid constant pool".equals(e.getMessage())) {
logger.warn("Broken constant pool: {}", path); // skip
} else {
throw e;
}
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Invalid Java .class file
- Unknown Java structure
- Unable to resolve class-filetype.
- Unable to resolve type.
- '${file.getAbsolutePath()}' not found.
AI-assisted analysis of Konloch/bytecode-viewer@31430e0033 (2026-09-05).
Data as JSON: /api/errors/18da61cb71f80736.
Report an issue: GitHub.