ClassFormatError: Unknown constant tag in class XY

后端 未结 2 601
梦谈多话
梦谈多话 2020-12-20 12:00

I have a piece of code in which I try to load a class during runtime. The code is not all selfwritten so I have some problems understanding the error which always appers aft

相关标签:
2条回答
  • 2020-12-20 12:43

    Answers to your questions:

    1. No

    2. Yes

    3. From Java Doc Thrown when the Java Virtual Machine attempts to read a class file and determines that the file is malformed or otherwise cannot be interpreted as a class file.

    0 讨论(0)
  • 2020-12-20 12:53

    The code you've written yourself is fine. The problem is that AP.class is a damaged class file -- hence the ClassFormatError.

    The error itself means that it failed to correctly decode the constant pool, a section of the class file structure that is much like a symbol table. See §4.4 of the Java Virtual Machine Specification:

    Java virtual machine instructions do not rely on the runtime layout of classes, interfaces, class instances, or arrays. Instead, instructions refer to symbolic information in the constant_pool table.

    All constant_pool table entries have the following general format:

    cp_info {
        u1 tag;
        u1 info[];
    }
    

    Each item in the constant_pool table must begin with a 1-byte tag indicating the kind of cp_info entry. The contents of the info array vary with the value of tag. The valid tags and their values are listed in Table 4.3. Each tag byte must be followed by two or more bytes giving information about the specific constant. The format of the additional information varies with the tag value.

    So, the error itself is telling you that the class has a constant pool table entry with an invalid tag, namely 63. Verifying with Table 4.3 mentioned above, indeed, this does not correspond to any documented kind of cp_info entry.

    Try to re-download AP.class. Given the obscure names (AP, as well as c from the stack trace), I'm going to assume you're trying to use some obfuscated code. Verify not only that the code you're trying to deal with is not further protected by some sort of encryption, but also that any preprocessing you do (e.g. deobfuscation) does not corrupt the data.

    0 讨论(0)
提交回复
热议问题