ifnonnull

Branch if reference not null

Bytecode

Type Description
u1 ifnonnull opcode = 0xC7 (199)
s2 branchoffset

Stack ..., value => ...

Description

The value must of type reference. It is popped from the oper-and stack. If value is not null, the unsigned branchbyte1 and branchbyte2 are used to construct a signed 16-bit offset, where the offset is calculated to be (branchbyte1 << 8) | branchbyte2. Execution then proceeds at that offset from the address of the opcode of this ifnonnull instruction. The target address must be that of an opcode of an instruction within the method that contains this ifnonnull instruction.

Otherwise, execution proceeds at the address of the instruction following this ifnonnull instruction.

Example
    aload_1          ; push the object reference in local variable 1 onto the stack
    ifnonnull Label ; if local variable isn't null, jump to Label
    return          ; return if local variable 1 is null
Label:
    ; execution continues here if local variable 1 is something other than null ...

Notes

Addresses are measured in bytes from the start of the bytecode (i.e. address 0 is the first byte in the bytecode of the currently executing method).