Question

Little question about the output generated from the javap command regarding the constant pool. When javap prints the pool it defines string constants as Asciz strings, which I understand means null terminated Ascii:

const #20 = Asciz       hello world;

This would imply that the length of the string is not known, and to parse you would read each byte until you encounter the null.

However, the length of constant pool string constants is defined by the two bytes preceding the string and there is no null appended. (Constant pool specification).

Does javap define strings as Asciz incorrectly or does Asciz have another meaning I'm not aware of?

Was it helpful?

Solution

See bug #6868539. It's fixed in OpenJDK7, now javap prints Utf8 instead.

OTHER TIPS

The const #20 is not the actual string, but rather the UTF8 defined characters used for your string. You probably have another constant which is a string that references the constant #20. The asciz constants are used for other things than strings such as field names etc. The actual info contains the UTF8 tag, the length and the bytes.

See http://java.sun.com/docs/books/jvms/second_edition/html/ClassFile.doc.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top