Exceptions from invalid constant pool indices in the API

- liangchenblue at gmail.com
Mon Apr 10 23:34:21 UTC 2023


When I was taking a peek at the conversion of javap to Classfile API,
I found that the old API has a feature that the API might be
interested in: a dedicated exception ConstantPoolException for invalid
constant pool indices, caused by incorrect types or out-of-bounds. We
currently throw IllegalArgumentException and IndexOutOfBoundsException
in the Classfile API, so it is a bit harder to catch such invalid
indices.

Javap is tolerant to invalid class file formats while the reading part
of Classfile API is not so much; in general, Classfile API fails fast
if it encounters invalid constant pool entries; this I agree, that
invalid entries render a classfile invalid, but maybe we can unify the
reading exceptions from ConstantPoolReader into a common type like in
the old API, so we can more easily report constant pool errors or skip
invalid but optional entries.

Chen Liang


More information about the classfile-api-dev mailing list