The InnerClasses attribute is a variable-length attribute in the attributes table of a ClassFile structure (§4.1).
If the constant pool of a class or interface C contains at least one CONSTANT_Class_info entry (§4.4.1) which represents a class or interface that is not a member of a package, then there must be exactly one InnerClasses attribute in the attributes table of the ClassFile structure for C.
The InnerClasses attribute has the following format:
InnerClasses_attribute {
u2 attribute_name_index;
u4 attribute_length;
u2 number_of_classes;
{ u2 inner_class_info_index;
u2 outer_class_info_index;
u2 inner_name_index;
u2 inner_class_access_flags;
} classes[number_of_classes];
}
The items of the InnerClasses_attribute structure are as follows:
-
attribute_name_index
The value of the
attribute_name_indexitem must be a valid index into theconstant_pooltable. Theconstant_poolentry at that index must be aCONSTANT_Utf8_infostructure (§4.4.7) representing the string "InnerClasses". -
attribute_length
The value of the
attribute_lengthitem indicates the length of the attribute, excluding the initial six bytes. -
number_of_classes
The value of the
number_of_classesitem indicates the number of entries in theclassesarray. -
classes[]
Every
CONSTANT_Class_infoentry in theconstant_pooltable which represents a class or interface C that is not a package member must have exactly one corresponding entry in theclassesarray.If a class or interface has members that are classes or interfaces, its
constant_pooltable (and hence itsInnerClassesattribute) must refer to each such member (JLS §13.1), even if that member is not otherwise mentioned by the class.In addition, the
constant_pooltable of every nested class and nested interface must refer to its enclosing class, so altogether, every nested class and nested interface will haveInnerClassesinformation for each enclosing class and for each of its own nested classes and interfaces.Each entry in the
classesarray contains the following four items:-
inner_class_info_index
The value of the
inner_class_info_indexitem must be a valid index into theconstant_pooltable. Theconstant_poolentry at that index must be aCONSTANT_Class_infostructure representing C. -
outer_class_info_index
If C is not a member of a class or an interface - that is, if C is a top-level class or interface (JLS §7.6) or a local class (JLS §14.3) or an anonymous class (JLS §15.9.5) - then the value of the
outer_class_info_indexitem must be zero.Otherwise, the value of the
outer_class_info_indexitem must be a valid index into theconstant_pooltable, and the entry at that index must be aCONSTANT_Class_infostructure representing the class or interface of which C is a member. The value of theouter_class_info_indexitem must not equal the the value of theinner_class_info_indexitem. -
inner_name_index
If C is anonymous (JLS §15.9.5), the value of the
inner_name_indexitem must be zero.Otherwise, the value of the
inner_name_indexitem must be a valid index into theconstant_pooltable, and the entry at that index must be aCONSTANT_Utf8_infostructure that represents the original simple name of C, as given in the source code from which thisclassfile was compiled. -
inner_class_access_flags
The value of the
inner_class_access_flagsitem is a mask of flags used to denote access permissions to and properties of class or interface C as declared in the source code from which thisclassfile was compiled. It is used by a compiler to recover the original information when source code is not available. The flags are specified in Table 4.7.6-A.Table 4.7.6-A. Nested class access and property flags
Flag Name Value Interpretation ACC_PUBLIC0x0001 Marked or implicitly publicin source.ACC_PRIVATE0x0002 Marked privatein source.ACC_PROTECTED0x0004 Marked protectedin source.ACC_STATIC0x0008 Marked or implicitly staticin source.ACC_FINAL0x0010 Marked or implicitly finalin source.ACC_INTERFACE0x0200 Was an interfacein source.ACC_ABSTRACT0x0400 Marked or implicitly abstractin source.ACC_SYNTHETIC0x1000 Declared synthetic; not present in the source code. ACC_ANNOTATION0x2000 Declared as an annotation type. ACC_ENUM0x4000 Declared as an enumtype.All bits of the
inner_class_access_flagsitem not assigned in Table 4.7.6-A are reserved for future use. They should be set to zero in generatedclassfiles and should be ignored by Java Virtual Machine implementations.
If a
classfile has a version number that is 51.0 or above, and has anInnerClassesattribute in itsattributestable, then for all entries in theclassesarray of theInnerClassesattribute, the value of theouter_class_info_indexitem must be zero if the value of theinner_name_indexitem is zero. -
Oracle's Java Virtual Machine implementation does not check the consistency of an InnerClasses attribute against a class file representing a class or interface referenced by the attribute.