Exceptions from invalid constant pool indices in the API

Brian Goetz brian.goetz at oracle.com
Tue Apr 11 00:15:39 UTC 2023


Good suggestion!

> On Apr 10, 2023, at 4:34 PM, liangchenblue at gmail.com wrote:
> 
> 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