ifnonnull 0xc7

Pops a reference; jumps if it is not null.

Opcode
0xc7 (199)
Family
Branches and switches
Operands
  • 2 bytes: signed branch offset
Length
3 bytes
Operand stack
…, value (reference) → …
Can throw
nothing at run time (beyond linking errors)

What it does

Pops a reference and jumps if it is not null. javac uses it for x == null and x != null, usually inverted to skip the then-part.

How often javac uses it

In JDK 25.0.5's java.base module, ifnonnull appears 6,443 times in 1,710 of its 7,391 classes: 0.33% of all instructions, the 55th most common of 194 opcodes in use. Some of the methods that use it: java.io.BufferedInputStream.getInIfOpen, java.io.BufferedReader.ensureOpen, java.io.BufferedReader$1.next, java.io.BufferedWriter.ensureOpen.

Example

From the sample classes, compiled by javac 25 with -g. Each Java line is shown above the bytecode it compiled to; ifnonnull 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

Related instructions

ifnull Pops a reference; jumps if it is null.if_acmpeq Pops two references; jumps if they are the same object.aconst_null Pushes null.

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