<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:Wingdings;
panose-1:5 0 0 0 0 0 0 0 0 0;}
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
font-size:10.0pt;
font-family:"Calibri",sans-serif;}
p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph
{mso-style-priority:34;
margin-top:0cm;
margin-right:0cm;
margin-bottom:0cm;
margin-left:36.0pt;
font-size:10.0pt;
font-family:"Calibri",sans-serif;}
span.EmailStyle19
{mso-style-type:personal-reply;
font-family:"Calibri",sans-serif;
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;
mso-ligatures:none;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
{page:WordSection1;}
/* List Definitions */
@list l0
{mso-list-id:1639728659;
mso-list-type:hybrid;
mso-list-template-ids:-1408051484 790648072 134807555 134807557 134807553 134807555 134807557 134807553 134807555 134807557;}
@list l0:level1
{mso-level-start-at:0;
mso-level-number-format:bullet;
mso-level-text:-;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:"Calibri",sans-serif;
mso-fareast-font-family:"Times New Roman";}
@list l0:level2
{mso-level-number-format:bullet;
mso-level-text:o;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:"Courier New";}
@list l0:level3
{mso-level-number-format:bullet;
mso-level-text:\F0A7 ;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:Wingdings;}
@list l0:level4
{mso-level-number-format:bullet;
mso-level-text:\F0B7 ;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:Symbol;}
@list l0:level5
{mso-level-number-format:bullet;
mso-level-text:o;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:"Courier New";}
@list l0:level6
{mso-level-number-format:bullet;
mso-level-text:\F0A7 ;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:Wingdings;}
@list l0:level7
{mso-level-number-format:bullet;
mso-level-text:\F0B7 ;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:Symbol;}
@list l0:level8
{mso-level-number-format:bullet;
mso-level-text:o;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:"Courier New";}
@list l0:level9
{mso-level-number-format:bullet;
mso-level-text:\F0A7 ;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:Wingdings;}
ol
{margin-bottom:0cm;}
ul
{margin-bottom:0cm;}
--></style>
</head>
<body lang="en-CZ" link="#0563C1" vlink="#954F72" style="word-wrap:break-word">
<div class="WordSection1">
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;mso-fareast-language:EN-US">I’ve tried to convert all CP related exceptions to a new ConstantPoolException, however
</span><span style="font-size:11.0pt">IllegalArgumentException</span><span style="font-size:11.0pt">
<span lang="EN-US">is still in the game (in javap) as a secondary exception thrown during validation of symbols.<o:p></o:p></span></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt">For example printing of Signature attribute or any ClassDesc can now fail with:<o:p></o:p></span></p>
<ul style="margin-top:0cm" type="disc">
<li class="MsoListParagraph" style="margin-left:0cm;mso-list:l0 level1 lfo1"><span style="font-size:11.0pt">IndexOutOfBoundsException</span><span lang="EN-US" style="font-size:11.0pt"> when the index is invalid</span><span lang="EN-US" style="font-size:11.0pt;mso-fareast-language:EN-US"><o:p></o:p></span></li><li class="MsoListParagraph" style="margin-left:0cm;mso-list:l0 level1 lfo1"><span style="font-size:11.0pt">IllegalArgumentException</span><span style="font-size:11.0pt">
<span lang="EN-US">when the CP entry is invalid</span></span><span lang="EN-US" style="font-size:11.0pt;mso-fareast-language:EN-US"><o:p></o:p></span></li><li class="MsoListParagraph" style="margin-left:0cm;mso-list:l0 level1 lfo1"><span style="font-size:11.0pt">IllegalArgumentException</span><span lang="EN-US" style="font-size:11.0pt"> when the symbol is invalid</span><span lang="EN-US" style="font-size:11.0pt;mso-fareast-language:EN-US"><o:p></o:p></span></li></ul>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;mso-fareast-language:EN-US">After merge of CP-related
</span><span style="font-size:11.0pt">IndexOutOfBoundsException</span><span lang="EN-US" style="font-size:11.0pt"> and
</span><span style="font-size:11.0pt">IllegalArgumentException</span><span style="font-size:11.0pt">
<span lang="EN-US">into</span></span><span lang="EN-US" style="font-size:11.0pt;mso-fareast-language:EN-US"> ConstantPoolException</span><span lang="EN-US" style="font-size:11.0pt"> we can get:<o:p></o:p></span></p>
<ul style="margin-top:0cm" type="disc">
<li class="MsoListParagraph" style="margin-left:0cm;mso-list:l0 level1 lfo1"><span lang="EN-US" style="font-size:11.0pt;mso-fareast-language:EN-US">ConstantPoolException</span><span lang="EN-US" style="font-size:11.0pt"> when the index is invalid</span><span lang="EN-US" style="font-size:11.0pt;mso-fareast-language:EN-US"><o:p></o:p></span></li><li class="MsoListParagraph" style="margin-left:0cm;mso-list:l0 level1 lfo1"><span lang="EN-US" style="font-size:11.0pt;mso-fareast-language:EN-US">ConstantPoolException</span><span lang="EN-US" style="font-size:11.0pt"> when the CP entry is invalid</span><span lang="EN-US" style="font-size:11.0pt;mso-fareast-language:EN-US"><o:p></o:p></span></li><li class="MsoListParagraph" style="margin-left:0cm;mso-list:l0 level1 lfo1"><span style="font-size:11.0pt">IllegalArgumentException</span><span lang="EN-US" style="font-size:11.0pt"> when the symbol fails validation</span><span lang="EN-US" style="font-size:11.0pt;mso-fareast-language:EN-US"><o:p></o:p></span></li></ul>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;mso-fareast-language:EN-US">Is it still worth to introduce a new exception when javap still must individually safeguard also
</span><span style="font-size:11.0pt">IllegalArgumentException</span><span lang="EN-US" style="font-size:11.0pt">s</span><span lang="EN-US" style="font-size:11.0pt;mso-fareast-language:EN-US"> ?<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;mso-fareast-language:EN-US">What about to replace CP-relate</span><span lang="EN-US" style="font-size:11.0pt">
</span><span style="font-size:11.0pt">IndexOutOfBoundsException</span><span lang="EN-US" style="font-size:11.0pt"> with</span><span lang="EN-US" style="font-size:11.0pt;mso-fareast-language:EN-US">
</span><span style="font-size:11.0pt">IllegalArgumentException</span><span lang="EN-US" style="font-size:11.0pt"> so we will have one single type of exception to catch when class reading?<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt">Or what if we make
</span><span lang="EN-US" style="font-size:11.0pt;mso-fareast-language:EN-US">ConstantPoolException a sub-class of
</span><span style="font-size:11.0pt">IllegalArgumentException</span><span lang="EN-US" style="font-size:11.0pt">?<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt">Thanks,<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt">Adam</span><span lang="EN-US" style="font-size:11.0pt;mso-fareast-language:EN-US"><o:p></o:p></span></p>
<p class="MsoListParagraph"><span lang="EN-US" style="font-size:11.0pt;mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal" style="margin-bottom:12.0pt"><b><span style="font-size:12.0pt;color:black">From:
</span></b><span style="font-size:12.0pt;color:black">classfile-api-dev <classfile-api-dev-retn@openjdk.org> on behalf of Brian Goetz <brian.goetz@oracle.com><br>
<b>Date: </b>Tuesday, 11 April 2023 2:15<br>
<b>To: </b>liangchenblue@gmail.com <liangchenblue@gmail.com><br>
<b>Cc: </b>classfile-api-dev@openjdk.org <classfile-api-dev@openjdk.org><br>
<b>Subject: </b>Re: Exceptions from invalid constant pool indices in the API<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt"><span style="font-size:11.0pt">Good suggestion!<br>
<br>
> On Apr 10, 2023, at 4:34 PM, liangchenblue@gmail.com wrote:<br>
> <br>
> When I was taking a peek at the conversion of javap to Classfile API,<br>
> I found that the old API has a feature that the API might be<br>
> interested in: a dedicated exception ConstantPoolException for invalid<br>
> constant pool indices, caused by incorrect types or out-of-bounds. We<br>
> currently throw IllegalArgumentException and IndexOutOfBoundsException<br>
> in the Classfile API, so it is a bit harder to catch such invalid<br>
> indices.<br>
> <br>
> Javap is tolerant to invalid class file formats while the reading part<br>
> of Classfile API is not so much; in general, Classfile API fails fast<br>
> if it encounters invalid constant pool entries; this I agree, that<br>
> invalid entries render a classfile invalid, but maybe we can unify the<br>
> reading exceptions from ConstantPoolReader into a common type like in<br>
> the old API, so we can more easily report constant pool errors or skip<br>
> invalid but optional entries.<br>
> <br>
> Chen Liang<o:p></o:p></span></p>
</div>
</div>
</body>
</html>