<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">
So, I think there are two reasons we might consider a more precise exception here. One is Chen’s concern of “what do I catch”, and the other is simply getting a more human-readable explanation of what went wrong. Exceptions like AIOOBE and IAE are often not
helpful in explaining what actually went wrong (what index? Into what? Where did the bad value come from?).
<div class=""><br class="">
</div>
<div class="">Part of this is the exception type (which helps both of these audiences), and part of this is the exception message (which helps only the latter.). We should probably do a pass and make sure we have informative error text in all throw points.
</div>
<div class=""><br class="">
</div>
<div class="">What do you mean “when the symbol fails validation”? <br class="">
<div><br class="">
<blockquote type="cite" class="">
<div class="">On Apr 13, 2023, at 9:00 AM, Adam Sotona <<a href="mailto:adam.sotona@oracle.com" class="">adam.sotona@oracle.com</a>> wrote:</div>
<br class="Apple-interchange-newline">
<div class="">
<div class="WordSection1" style="page: WordSection1; caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;">
<div style="margin: 0cm; font-size: 10pt; font-family: Calibri, sans-serif;" class="">
<span lang="EN-US" style="font-size: 11pt;" class="">I’ve tried to convert all CP related exceptions to a new ConstantPoolException, however<span class="Apple-converted-space"> </span></span><span style="font-size: 11pt;" class="">IllegalArgumentException</span><span style="font-size: 11pt;" class=""><span class="Apple-converted-space"> </span><span lang="EN-US" class="">is
still in the game (in javap) as a secondary exception thrown during validation of symbols.<o:p class=""></o:p></span></span></div>
<div style="margin: 0cm; font-size: 10pt; font-family: Calibri, sans-serif;" class="">
<span lang="EN-US" style="font-size: 11pt;" class="">For example printing of Signature attribute or any ClassDesc can now fail with:<o:p class=""></o:p></span></div>
<ul type="disc" style="margin-bottom: 0cm; margin-top: 0cm;" class="">
<li class="MsoListParagraph" style="margin: 0cm; font-size: 10pt; font-family: Calibri, sans-serif;">
<span style="font-size: 11pt;" class="">IndexOutOfBoundsException</span><span lang="EN-US" style="font-size: 11pt;" class=""><span class="Apple-converted-space"> </span>when the index is invalid</span><span lang="EN-US" style="font-size: 11pt;" class=""><o:p class=""></o:p></span></li><li class="MsoListParagraph" style="margin: 0cm; font-size: 10pt; font-family: Calibri, sans-serif;">
<span style="font-size: 11pt;" class="">IllegalArgumentException</span><span style="font-size: 11pt;" class=""><span class="Apple-converted-space"> </span><span lang="EN-US" class="">when the CP entry is invalid</span></span><span lang="EN-US" style="font-size: 11pt;" class=""><o:p class=""></o:p></span></li><li class="MsoListParagraph" style="margin: 0cm; font-size: 10pt; font-family: Calibri, sans-serif;">
<span style="font-size: 11pt;" class="">IllegalArgumentException</span><span lang="EN-US" style="font-size: 11pt;" class=""><span class="Apple-converted-space"> </span>when the symbol is invalid</span><span lang="EN-US" style="font-size: 11pt;" class=""><o:p class=""></o:p></span></li></ul>
<div style="margin: 0cm; font-size: 10pt; font-family: Calibri, sans-serif;" class="">
<span lang="EN-US" style="font-size: 11pt;" class=""><o:p class=""> </o:p></span></div>
<div style="margin: 0cm; font-size: 10pt; font-family: Calibri, sans-serif;" class="">
<span lang="EN-US" style="font-size: 11pt;" class="">After merge of CP-related<span class="Apple-converted-space"> </span></span><span style="font-size: 11pt;" class="">IndexOutOfBoundsException</span><span lang="EN-US" style="font-size: 11pt;" class=""><span class="Apple-converted-space"> </span>and<span class="Apple-converted-space"> </span></span><span style="font-size: 11pt;" class="">IllegalArgumentException</span><span style="font-size: 11pt;" class=""><span class="Apple-converted-space"> </span><span lang="EN-US" class="">into</span></span><span lang="EN-US" style="font-size: 11pt;" class=""><span class="Apple-converted-space"> </span>ConstantPoolException</span><span lang="EN-US" style="font-size: 11pt;" class=""><span class="Apple-converted-space"> </span>we
can get:<o:p class=""></o:p></span></div>
<ul type="disc" style="margin-bottom: 0cm; margin-top: 0cm;" class="">
<li class="MsoListParagraph" style="margin: 0cm; font-size: 10pt; font-family: Calibri, sans-serif;">
<span lang="EN-US" style="font-size: 11pt;" class="">ConstantPoolException</span><span lang="EN-US" style="font-size: 11pt;" class=""><span class="Apple-converted-space"> </span>when the index is invalid</span><span lang="EN-US" style="font-size: 11pt;" class=""><o:p class=""></o:p></span></li><li class="MsoListParagraph" style="margin: 0cm; font-size: 10pt; font-family: Calibri, sans-serif;">
<span lang="EN-US" style="font-size: 11pt;" class="">ConstantPoolException</span><span lang="EN-US" style="font-size: 11pt;" class=""><span class="Apple-converted-space"> </span>when the CP entry is invalid</span><span lang="EN-US" style="font-size: 11pt;" class=""><o:p class=""></o:p></span></li><li class="MsoListParagraph" style="margin: 0cm; font-size: 10pt; font-family: Calibri, sans-serif;">
<span style="font-size: 11pt;" class="">IllegalArgumentException</span><span lang="EN-US" style="font-size: 11pt;" class=""><span class="Apple-converted-space"> </span>when the symbol fails validation</span><span lang="EN-US" style="font-size: 11pt;" class=""><o:p class=""></o:p></span></li></ul>
<div style="margin: 0cm; font-size: 10pt; font-family: Calibri, sans-serif;" class="">
<span lang="EN-US" style="font-size: 11pt;" class=""><o:p class=""> </o:p></span></div>
<div style="margin: 0cm; font-size: 10pt; font-family: Calibri, sans-serif;" class="">
<span lang="EN-US" style="font-size: 11pt;" class="">Is it still worth to introduce a new exception when javap still must individually safeguard also<span class="Apple-converted-space"> </span></span><span style="font-size: 11pt;" class="">IllegalArgumentException</span><span lang="EN-US" style="font-size: 11pt;" class="">s</span><span lang="EN-US" style="font-size: 11pt;" class=""><span class="Apple-converted-space"> </span>?<o:p class=""></o:p></span></div>
<div style="margin: 0cm; font-size: 10pt; font-family: Calibri, sans-serif;" class="">
<span lang="EN-US" style="font-size: 11pt;" class=""><o:p class=""> </o:p></span></div>
<div style="margin: 0cm; font-size: 10pt; font-family: Calibri, sans-serif;" class="">
<span lang="EN-US" style="font-size: 11pt;" class="">What about to replace CP-relate</span><span lang="EN-US" style="font-size: 11pt;" class=""><span class="Apple-converted-space"> </span></span><span style="font-size: 11pt;" class="">IndexOutOfBoundsException</span><span lang="EN-US" style="font-size: 11pt;" class=""><span class="Apple-converted-space"> </span>with</span><span lang="EN-US" style="font-size: 11pt;" class=""><span class="Apple-converted-space"> </span></span><span style="font-size: 11pt;" class="">IllegalArgumentException</span><span lang="EN-US" style="font-size: 11pt;" class=""><span class="Apple-converted-space"> </span>so
we will have one single type of exception to catch when class reading?<o:p class=""></o:p></span></div>
<div style="margin: 0cm; font-size: 10pt; font-family: Calibri, sans-serif;" class="">
<span lang="EN-US" style="font-size: 11pt;" class="">Or what if we make<span class="Apple-converted-space"> </span></span><span lang="EN-US" style="font-size: 11pt;" class="">ConstantPoolException a sub-class of<span class="Apple-converted-space"> </span></span><span style="font-size: 11pt;" class="">IllegalArgumentException</span><span lang="EN-US" style="font-size: 11pt;" class="">?<o:p class=""></o:p></span></div>
<div style="margin: 0cm; font-size: 10pt; font-family: Calibri, sans-serif;" class="">
<span lang="EN-US" style="font-size: 11pt;" class=""><o:p class=""> </o:p></span></div>
<div style="margin: 0cm; font-size: 10pt; font-family: Calibri, sans-serif;" class="">
<span lang="EN-US" style="font-size: 11pt;" class="">Thanks,<o:p class=""></o:p></span></div>
<div style="margin: 0cm; font-size: 10pt; font-family: Calibri, sans-serif;" class="">
<span lang="EN-US" style="font-size: 11pt;" class="">Adam</span><span lang="EN-US" style="font-size: 11pt;" class=""><o:p class=""></o:p></span></div>
<div style="margin: 0cm 0cm 0cm 36pt; font-size: 10pt; font-family: Calibri, sans-serif;" class="">
<span lang="EN-US" style="font-size: 11pt;" class=""><o:p class=""> </o:p></span></div>
<div style="border-style: solid none none; border-top-width: 1pt; border-top-color: rgb(181, 196, 223); padding: 3pt 0cm 0cm;" class="">
<p class="MsoNormal" style="margin: 0cm 0cm 12pt; font-size: 10pt; font-family: Calibri, sans-serif;">
<b class=""><span style="font-size: 12pt;" class="">From:<span class="Apple-converted-space"> </span></span></b><span style="font-size: 12pt;" class="">classfile-api-dev <<a href="mailto:classfile-api-dev-retn@openjdk.org" class="">classfile-api-dev-retn@openjdk.org</a>>
on behalf of Brian Goetz <<a href="mailto:brian.goetz@oracle.com" class="">brian.goetz@oracle.com</a>><br class="">
<b class="">Date:<span class="Apple-converted-space"> </span></b>Tuesday, 11 April 2023 2:15<br class="">
<b class="">To:<span class="Apple-converted-space"> </span></b><a href="mailto:liangchenblue@gmail.com" class="">liangchenblue@gmail.com</a> <<a href="mailto:liangchenblue@gmail.com" class="">liangchenblue@gmail.com</a>><br class="">
<b class="">Cc:<span class="Apple-converted-space"> </span></b><a href="mailto:classfile-api-dev@openjdk.org" class="">classfile-api-dev@openjdk.org</a> <<a href="mailto:classfile-api-dev@openjdk.org" class="">classfile-api-dev@openjdk.org</a>><br class="">
<b class="">Subject:<span class="Apple-converted-space"> </span></b>Re: Exceptions from invalid constant pool indices in the API<o:p class=""></o:p></span></p>
</div>
<div class="">
<p class="MsoNormal" style="margin: 0cm 0cm 12pt; font-size: 10pt; font-family: Calibri, sans-serif;">
<span style="font-size: 11pt;" class="">Good suggestion!<br class="">
<br class="">
> On Apr 10, 2023, at 4:34 PM, <a href="mailto:liangchenblue@gmail.com" class="">
liangchenblue@gmail.com</a> wrote:<br class="">
><span class="Apple-converted-space"> </span><br class="">
> When I was taking a peek at the conversion of javap to Classfile API,<br class="">
> I found that the old API has a feature that the API might be<br class="">
> interested in: a dedicated exception ConstantPoolException for invalid<br class="">
> constant pool indices, caused by incorrect types or out-of-bounds. We<br class="">
> currently throw IllegalArgumentException and IndexOutOfBoundsException<br class="">
> in the Classfile API, so it is a bit harder to catch such invalid<br class="">
> indices.<br class="">
><span class="Apple-converted-space"> </span><br class="">
> Javap is tolerant to invalid class file formats while the reading part<br class="">
> of Classfile API is not so much; in general, Classfile API fails fast<br class="">
> if it encounters invalid constant pool entries; this I agree, that<br class="">
> invalid entries render a classfile invalid, but maybe we can unify the<br class="">
> reading exceptions from ConstantPoolReader into a common type like in<br class="">
> the old API, so we can more easily report constant pool errors or skip<br class="">
> invalid but optional entries.<br class="">
><span class="Apple-converted-space"> </span><br class="">
> Chen Liang</span></p>
</div>
</div>
</div>
</blockquote>
</div>
<br class="">
</div>
</body>
</html>