{"record":{"id":"414a91f11be8703d","repo":"Konloch/bytecode-viewer","slug":"unknown-java-structure","errorCode":null,"errorMessage":"Unknown Java structure","messagePattern":"Unknown Java structure","errorType":"exception","errorClass":"ClassFileFormatException","httpStatus":null,"severity":"error","filePath":"src/main/java/the/bytecode/club/bytecodeviewer/decompilers/jdgui/JDGUIClassFileUtil.java","lineNumber":66,"sourceCode":"            if (magic != ClassFileReader.JAVA_MAGIC_NUMBER)\n            {\n                throw new ClassFileFormatException(\"Invalid Java .class file\");\n            }\n\n            /* 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","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/Konloch/bytecode-viewer/blob/31430e0033fa220db566b5ef461256727ff6793b/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/jdgui/JDGUIClassFileUtil.java#L48-L84","documentation":"After parsing the constant pool, ExtractDirectoryPath reads this_class, an index into the constants array. If the index exceeds the array bounds, the file's structure is inconsistent with the JVM class-file spec, so a ClassFileFormatException('Unknown Java structure') is thrown. In practice this means the file is malformed, truncated mid-header, or not really a class file that got past the magic check.","triggerScenarios":"ExtractDirectoryPath on a corrupt/truncated class file where parsing stops early (DeserializeConstants returns early on an unknown tag, leaving constants shorter than expected) and the subsequent this_class index exceeds constants.length; also hand-crafted or obfuscated files with out-of-range cp indices.","commonSituations":"Files truncated by incomplete extraction or transfer; classes produced by non-standard tools/old obfuscators emitting constant-pool tags this parser does not know (default case bails out early, shrinking the array); fuzzed or edited binaries.","solutions":["Recompile or re-obtain a clean copy of the class file; the bytes are structurally invalid.","Check that the file was fully extracted (no truncation) — compare size against the source JAR entry.","Re-run the file through a spec-compliant parser (e.g. javap -v or ASM) to pinpoint where the structure diverges.","If obfuscated/packed, deobfuscate/depack first so the constant pool uses standard tags the simple parser recognizes.","Catch ClassFileFormatException and skip the file in batch processing."],"exampleFix":"// before\nString dir = JDGUIClassFileUtil.ExtractDirectoryPath(path); // throws on malformed file\n\n// after\ntry {\n    String dir = JDGUIClassFileUtil.ExtractDirectoryPath(path);\n} catch (org.jd.core.v1.service.deserializer.classfile.ClassFileFormatException e) {\n    // malformed/unrecognized structure: log and skip this file\n}","handlingStrategy":"try-catch","validationCode":"ProcessBuilder pb = new ProcessBuilder(\"javap\", \"-verify\", path);\npb.inheritIO();\nint rc = pb.start().waitFor();\nif (rc != 0) throw new IllegalStateException(\"Class file structurally invalid: \" + path);","typeGuard":null,"tryCatchPattern":"try {\n    String dir = JDGUIClassFileUtil.ExtractDirectoryPath(path);\n} catch (org.jd.core.v1.service.deserializer.classfile.ClassFileFormatException e) {\n    if (\"Unknown Java structure\".equals(e.getMessage())) {\n        logger.warn(\"Malformed class structure: {}\", path); // skip file\n    } else {\n        throw e;\n    }\n}","preventionTips":["Validate class files with a spec-compliant verifier (javap, ASM CheckClassAdapter) before parsing.","Ensure files are fully extracted — truncated files commonly fail here.","Avoid feeding output of custom/partial bytecode rewriters to this lightweight parser.","Treat unknown constant-pool tags as a signal the file needs preprocessing (deobfuscation) first.","Process files individually in a loop with per-file exception handling."],"tags":["java","class-format","corrupt-file","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-12T22:17:10.623Z"}