aconst_null 0x01

Pushes null.

Opcode
0x01 (1)
Family
Constants
Operands
none
Length
1 byte
Operand stack
… → …, null
Can throw
nothing at run time (beyond linking errors)

What it does

The null literal. Tests against null use ifnull and ifnonnull instead of loading null and comparing.

How often javac uses it

In JDK 25.0.5's java.base module, aconst_null appears 9,304 times in 1,998 of its 7,391 classes: 0.48% of all instructions, the 43rd most common of 194 opcodes in use. Some of the methods that use it: java.io.BufferedInputStream.close, java.io.BufferedReader.readLine, java.io.BufferedReader$1.<init>, java.io.BufferedWriter.close.

Examples

From the sample classes, compiled by javac 25 with -g. Each Java line is shown above the bytecode it compiled to; aconst_null is highlighted.

static String cast(Object o) in Tour, compiled by javac 25
96if (o == null) throw new IllegalArgumentException("null");
0aload_0 // o
4new #57// IllegalArgumentException
7dup
8ldc #59// "null"
10invokespecial #61// new IllegalArgumentException(String)
97if (!(o instanceof CharSequence)) return null;
14aload_0 // o
15instanceof #64// CharSequence
98return (String) o;
23aload_0 // o
24checkcast #16// String

Open in the viewer

public Comparable max() in Numbers, compiled by javac 25
21T best = null;
1astore_1 // best
22for (T t : items) if (best == null || t.compareTo(best) > 0) best = t;
2aload_0 // this
3getfield #10// Numbers.items : List
6invokeinterface #26, 1// List.iterator() : Iterator
… 17 instructions after

Open in the viewer

Related instructions

ifnull Pops a reference; jumps if it is null.ifnonnull Pops a reference; jumps if it is not null.iconst_0 Pushes the int constant 0.

Specification: JVMS §6.5, aconst_null (Java SE 25).