java: Harden constant pool helpers

Check constant pool entry tag and assert out on failure.

Signed-off-by: Pekka Enberg <penberg@kernel.org>