---
spec: JVMS
title: "The Java Virtual Machine Specification"
edition: "Java SE 26 Edition"
java_version: 26
chapter: "Chapter 5. Loading, Linking, and Initializing"
section: "5.3.5"
heading: "5.3.5. Deriving a Class from a class File Representation"
parent: "5.3. Creation and Loading"
source: https://docs.oracle.com/javase/specs/jvms/se26/html/jvms-5.html#jvms-5.3.5
id: "5.3.5"
url: https://jvm.obfuscated.software/jvms/se26/5.3.5.html
raw: https://jvm.obfuscated.software/jvms/se26/5.3.5.md
---

# 5.3.5. Deriving a Class from a `class` File Representation

Class loaders require the cooperation of the Java Virtual Machine to derive and create a class or interface from a binary representation provided by the loader ([§5.3.1](5.3.1.md), [§5.3.2](5.3.2.md)). The following steps are used to derive a class or interface C denoted by `N` from a purported representation in `class` file format when requested by a class loader `L`.

1. First, the Java Virtual Machine determines whether the request by class loader `L` to derive a class or interface denoted by `N` is permitted.

   If `L` has already been recorded as an initiating loader of a class or interface denoted by `N`, derivation throws a `LinkageError`.

   If the Java Virtual Machine is already in the process of deriving a class or interface denoted by `N` as requested by class loader `L`, derivation throws a `ClassCircularityError`.

2. Next, the Java Virtual Machine attempts to parse the purported representation. The purported representation may not in fact be a valid representation of C, so derivation must detect the following problems:

   - If the purported representation is not a `ClassFile` structure ([§4.1](4.1.md), [§4.8](4.8.md)), derivation throws a `ClassFormatError`.

   - Otherwise, if the purported representation is not of a supported major or minor version ([§4.1](4.1.md)), derivation throws an `UnsupportedClassVersionError`.

     `UnsupportedClassVersionError`, a subclass of `ClassFormatError`, was introduced in JDK 1.2 to enable easy identification of a `ClassFormatError` caused by an attempt to load a class whose representation uses an unsupported version of the `class` file format. In JDK 1.1 and earlier, an instance of `NoClassDefFoundError` or `ClassFormatError` was 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 or interface named `N`, derivation throws a `NoClassDefFoundError`.

     This occurs when the purported representation has either a `this_class` item which specifies a name other than `N`, or an `access_flags` item which has the `ACC_MODULE` flag set.

3. 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](5.4.3.1.md), with `L` acting as the defining loader of C. Note that if C is an interface it must have `Object` as its direct superclass, which must already have been loaded. Only `Object` has no direct superclass.

   Any exception that can be thrown as a result of failure of class or interface resolution can be thrown as a result of derivation. In addition, derivation must detect the following problems:

   - If the class or interface named as the direct superclass of C is in fact an interface or a `final` class, derivation throws an `IncompatibleClassChangeError`.

   - Otherwise, if the class named as the direct superclass of C has a `PermittedSubclasses` attribute ([§4.7.31](4.7.31.md)) and any of the following is true, derivation throws an `IncompatibleClassChangeError`:

     - The superclass is in a different run-time module than C ([§5.3.6](5.3.6.md)).
     - C does not have its `ACC_PUBLIC` flag set ([§4.1](4.1.md)) and the superclass is in a different run-time package than C ([§5.3](5.3.md)).
     - No entry in the `classes` array of the superclass's `PermittedSubclasses` attribute refers to a class or interface with the name `N`.

   - Otherwise, if C is a class and some instance method declared in C can override ([§5.4.5](5.4.5.md)) a `final` instance method declared in a superclass of C, derivation throws an `IncompatibleClassChangeError`.

4. 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](5.4.3.1.md), with `L` acting as the defining loader of C.

   Any exception that can be thrown as a result of failure of class or interface resolution can be thrown as a result of derivation. In addition, derivation must detect the following problems:

   - If any class or interface named as a direct superinterface of C is not in fact an interface, derivation throws an `IncompatibleClassChangeError`.

   - Otherwise, for each direct superinterface named by C, if the superinterface has a `PermittedSubclasses` attribute ([§4.7.31](4.7.31.md)) and any of the following is true, derivation throws an `IncompatibleClassChangeError`:

     - The superinterface is in a different run-time module than C.
     - C does not have its `ACC_PUBLIC` flag set ([§4.1](4.1.md)) and the superinterface is in a different run-time package than C.
     - No entry in the `classes` array of the superinterface's `PermittedSubclasses` attribute refers to a class or interface with the name `N`.

If no exception is thrown in steps 1-4, then derivation of the class or interface C succeeds. The Java Virtual Machine marks C to have `L` as its defining loader, records that `L` is an initiating loader of C ([§5.3.4](5.3.4.md)), and creates C in the method area ([§2.5.4](2.5.4.md)).

When derivation succeeds, the process of loading and creating C is not complete until every class loader that was involved in loading C (directly or indirectly) returns C as its result. Depending on the behavior of user-defined class loaders, the process of loading and creating C may yet fail ([§5.3.2](5.3.2.md)).

If an exception is thrown in steps 1-4, then derivation of the class or interface C fails with that exception.

Requests to derive a class or interface may be made concurrently by class loader code executing in multiple threads, but the derivation process is sequential. The Java Virtual Machine implementation ensures that only one request by a given class loader to derive a class or interface of a given name is processed at a time, while all other such requests wait until the first request is complete.

As specified by the derivation process, if the first request is successful, no subsequent requests will be permitted. The `ClassLoader` API provides mechanisms to synchronize derivation requests and cache successful results so that redundant derivation requests do not occur.
