---
spec: JVMS
title: "The Java Virtual Machine Specification"
edition: "Java SE 20 Edition"
java_version: 20
chapter: "Chapter 4. The class File Format"
section: "4.10.2.1"
heading: "4.10.2.1. The Process of Verification by Type Inference"
parent: "4.10.2. Verification by Type Inference"
source: https://docs.oracle.com/javase/specs/jvms/se20/html/jvms-4.html#jvms-4.10.2.1
id: "4.10.2.1"
url: https://jvm.obfuscated.software/jvms/se20/4.10.2.1.html
raw: https://jvm.obfuscated.software/jvms/se20/4.10.2.1.md
---

# 4.10.2.1. The Process of Verification by Type Inference

During linking, the verifier checks the `code` array of the `Code` attribute for each method of the `class` file by performing data-flow analysis on each method. The verifier ensures that at any given point in the program, no matter what code path is taken to reach that point, all of the following are true:

- The operand stack is always the same size and contains the same types of values.
- No local variable is accessed unless it is known to contain a value of an appropriate type.
- Methods are invoked with the appropriate arguments.
- Fields are assigned only using values of appropriate types.
- All opcodes have appropriately typed arguments on the operand stack and in the local variable array.

For efficiency reasons, certain tests that could in principle be performed by the verifier are delayed until the first time the code for the method is actually invoked. In so doing, the verifier avoids loading `class` files unless it has to.

For example, if a method invokes another method that returns an instance of class A, and that instance is assigned only to a field of the same type, the verifier does not bother to check if the class A actually exists. However, if it is assigned to a field of the type B, the definitions of both A and B must be loaded in to ensure that A is a subclass of B.
