---
spec: JVMS
title: "The Java Virtual Machine Specification"
edition: "Java SE 26 Edition"
java_version: 26
chapter: "Chapter 4. The class File Format"
section: "4.7.10"
heading: "4.7.10. The SourceFile Attribute"
parent: "4.7. Attributes"
source: https://docs.oracle.com/javase/specs/jvms/se26/html/jvms-4.html#jvms-4.7.10
id: "4.7.10"
url: https://jvm.obfuscated.software/jvms/se26/4.7.10.html
raw: https://jvm.obfuscated.software/jvms/se26/4.7.10.md
---

# 4.7.10. The `SourceFile` Attribute

The `SourceFile` attribute is an optional fixed-length attribute in the `attributes` table of a `ClassFile` structure ([§4.1](4.1.md)).

There may be at most one `SourceFile` attribute in the `attributes` table of a `ClassFile` structure.

The `SourceFile` attribute has the following format:

```
SourceFile_attribute {
    u2 attribute_name_index;
    u4 attribute_length;
    u2 sourcefile_index;
}
```

The items of the `SourceFile_attribute` structure are as follows:

- **attribute_name_index**

  The value of the `attribute_name_index` item must be a valid index into the `constant_pool` table. The `constant_pool` entry at that index must be a `CONSTANT_Utf8_info` structure ([§4.4.7](4.4.7.md)) representing the string "`SourceFile`".

- **attribute_length**

  The value of the `attribute_length` item must be two.

- **sourcefile_index**

  The value of the `sourcefile_index` item must be a valid index into the `constant_pool` table. The `constant_pool` entry at that index must be a `CONSTANT_Utf8_info` structure representing a string.

  The string referenced by the `sourcefile_index` item will be interpreted as indicating the name of the source file from which this `class` file was compiled. It will not be interpreted as indicating the name of a directory containing the file or an absolute path name for the file; such platform-specific additional information must be supplied by the run-time interpreter or development tool at the time the file name is actually used.
