The following steps are used to derive a Class object for the nonarray class or interface C denoted by N using loader L from a purported representation in class file format.
-
First, the Java Virtual Machine determines whether it has already recorded that
Lis an initiating loader of a class or interface denoted byN. If so, this creation attempt is invalid and loading throws aLinkageError. -
Otherwise, the Java Virtual Machine attempts to parse the purported representation. However, the purported representation may not in fact be a valid representation of C.
This phase of loading must detect the following errors:
-
If the purported representation is not a
ClassFilestructure (§4.1, §4.8), loading throws an instance ofClassFormatError. -
Otherwise, if the purported representation is not of a supported major or minor version (§4.1), loading throws an instance of
UnsupportedClassVersionError.UnsupportedClassVersionError, a subclass ofClassFormatError, was introduced to enable easy identification of aClassFormatErrorcaused by an attempt to load a class whose representation uses an unsupported version of theclassfile format. In JDK 1.1 and earlier, an instance ofNoClassDefFoundErrororClassFormatErrorwas thrown in case of an unsupported version, depending on whether the class was being loaded by the system class loader or a user-defined class loader. -
Otherwise, if the purported representation does not actually represent a class named
N, loading throws an instance ofNoClassDefFoundErroror an instance of one of its subclasses.This occurs when the purported representation has either a
this_classitem which specifies a name other thanN, or anaccess_flagsitem which has theACC_MODULEflag set.
-
-
If C has a direct superclass, the symbolic reference from C to its direct superclass is resolved using the algorithm of §5.4.3.1. Note that if C is an interface it must have
Objectas its direct superclass, which must already have been loaded. OnlyObjecthas no direct superclass.Any exceptions that can be thrown due to class or interface resolution can be thrown as a result of this phase of loading. In addition, this phase of loading must detect the following errors:
- If the class or interface named as the direct superclass of C is in fact an interface, loading throws an
IncompatibleClassChangeError. - Otherwise, if any of the superclasses of C is C itself, loading throws a
ClassCircularityError.
- If the class or interface named as the direct superclass of C is in fact an interface, loading throws an
-
If C has any direct superinterfaces, the symbolic references from C to its direct superinterfaces are resolved using the algorithm of §5.4.3.1.
Any exceptions that can be thrown due to class or interface resolution can be thrown as a result of this phase of loading. In addition, this phase of loading must detect the following errors:
- If any of the classes or interfaces named as direct superinterfaces of C is not in fact an interface, loading throws an
IncompatibleClassChangeError. - Otherwise, if any of the superinterfaces of C is C itself, loading throws a
ClassCircularityError.
- If any of the classes or interfaces named as direct superinterfaces of C is not in fact an interface, loading throws an
-
The Java Virtual Machine marks C as having
Las its defining class loader and records thatLis an initiating loader of C (§5.3.4).