Exceptions from invalid constant pool indices in the API

Adam Sotona adam.sotona at oracle.com
Thu Apr 13 13:00:46 UTC 2023


I’ve tried to convert all CP related exceptions to a new ConstantPoolException, however IllegalArgumentException is still in the game  (in javap) as a secondary exception thrown during validation of symbols.
For example printing of Signature attribute or any ClassDesc can now fail with:

  *   IndexOutOfBoundsException when the index is invalid
  *   IllegalArgumentException when the CP entry is invalid
  *   IllegalArgumentException when the symbol is invalid

After merge of CP-related IndexOutOfBoundsException and IllegalArgumentException into ConstantPoolException we can get:

  *   ConstantPoolException when the index is invalid
  *   ConstantPoolException when the CP entry is invalid
  *   IllegalArgumentException when the symbol fails validation

Is it still worth to introduce a new exception when javap still must individually safeguard also IllegalArgumentExceptions ?

What about to replace CP-relate IndexOutOfBoundsException with IllegalArgumentException so we will have one single type of exception to catch when class reading?
Or what if we make ConstantPoolException a sub-class of IllegalArgumentException?

Thanks,
Adam


From: classfile-api-dev <classfile-api-dev-retn at openjdk.org> on behalf of Brian Goetz <brian.goetz at oracle.com>
Date: Tuesday, 11 April 2023 2:15
To: liangchenblue at gmail.com <liangchenblue at gmail.com>
Cc: classfile-api-dev at openjdk.org <classfile-api-dev at openjdk.org>
Subject: Re: Exceptions from invalid constant pool indices in the API
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/classfile-api-dev/attachments/20230413/e91e440d/attachment-0001.htm>


More information about the classfile-api-dev mailing list