The Synthetic attribute is a fixed-length attribute in the attributes table of a ClassFile, field_info, or method_info structure (§4.1, §4.5, §4.6). A class member that does not appear in the source code must be marked using a Synthetic attribute, or else it must have its ACC_SYNTHETIC flag set. The only exceptions to this requirement are compiler-generated members which are not considered implementation artifacts, namely:
- an instance initialization method representing a default constructor of the Java programming language (§2.9.1)
- a class or interface initialization method (§2.9.2)
- the implicitly declared members of enum and record classes (JLS §8.9.3, JLS §8.10.3)
The Synthetic attribute was introduced in JDK 1.1 to support nested classes and interfaces.
It is a limitation of the class file format that only formal parameters and modules can be flagged as ACC_MANDATED (§4.7.24, §4.7.25) to indicate that, despite being compiler-generated, they are not considered implementation artifacts. There is no way to flag other compiler-generated constructs so that they too are not considered implementation artifacts (JLS §13.1). This limitation means that reflective APIs of the Java SE Platform may not accurately indicate the "mandated" status of such constructs.
The Synthetic attribute has the following format:
Synthetic_attribute {
u2 attribute_name_index;
u4 attribute_length;
}
The items of the Synthetic_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 "Synthetic". -
attribute_length
The value of the
attribute_lengthitem must be zero.