<html xmlns:v="urn:schemas-microsoft-com:vml" 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)">
<!--[if !mso]><style>v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style><![endif]--><style><!--
/* Font Definitions */
@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:11.0pt;
        font-family:"Calibri",sans-serif;}
p.xmsonormal, li.xmsonormal, div.xmsonormal
        {mso-style-name:x_msonormal;
        margin:0cm;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
.MsoChpDefault
        {mso-style-type:export-only;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:70.85pt 70.85pt 70.85pt 70.85pt;}
div.WordSection1
        {page:WordSection1;}
--></style>
</head>
<body lang="FR" style="word-wrap:break-word">
<div class="WordSection1">
<p class="MsoNormal">Hello,</p>
<p class="MsoNormal">I sent an email half a month ago explaining that CompletionInfo#source() can be null even if nothing is explained in the doc about this. But nobody responded</p>
<p class="MsoNormal">Now, I also noticed that with this specific code, source and remaining are nearly equal</p>
<p class="MsoNormal"><br>
```</p>
<p class="MsoNormal">import jdk.jshell.*;</p>
<p class="MsoNormal">var shell = JShell.create()</p>
<p class="MsoNormal">var completion = shell.sourceCodeAnalysis().analyzeCompletion("while(true)")</p>
<p class="MsoNormal">println(completion.source()) // "while(true);"</p>
<p class="MsoNormal">println(completion.remaining()) // "while(true)\n"</p>
<p class="MsoNormal">```</p>
<p class="MsoNormal">Not only this is weird, but if I have for example " for(int i = 0; i < 10; i++) ", my program will use the result of remaining to feed the next exec, until there is nothing left, but since here source = remaining, it will execute this for
 loop again and again.</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I would want if possible why those two cases exist, and if it is possible to enhance the doc so people in the future don’t spend hours trying to figure out why there is a null in the code or why remaining = source.</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="xmsonormal" style="mso-margin-top-alt:0cm;margin-right:7.5pt;margin-bottom:7.5pt;margin-left:0cm">
Regards,</p>
<p class="xmsonormal" style="mso-margin-top-alt:0cm;margin-right:7.5pt;margin-bottom:7.5pt;margin-left:0cm">
Tom.</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><img width="615" height="2" style="width:6.4062in;height:.0208in" id="Horizontal_x0020_Line_x0020_1" src="cid:image001.png@01DA1286.BC656450"><o:p></o:p></p>
<div id="divRplyFwdMsg">
<p class="MsoNormal"><b><span style="color:black">De :</span></b><span style="color:black"> core-libs-dev <core-libs-dev-retn@openjdk.org> de la part de tom L <tom_L64@hotmail.com><br>
<b>Envoyé :</b> Monday, October 23, 2023 8:26:11 PM<br>
<b>À :</b> core-libs-dev@openjdk.org <core-libs-dev@openjdk.org><br>
<b>Objet :</b> [JShell] SourceCodeAnalysis.CompletionInfo#source() can be null but the doc doesn't say anything about it</span>
<o:p></o:p></p>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="xmsonormal">Hello,</p>
<p class="xmsonormal">I have a problem with JShell, I don’t know if it should go in this mailing list.</p>
<p class="xmsonormal">On JDK 21 (should be the same for any JDK version 9+), Windows 11, with this following code :</p>
<p class="xmsonormal">```</p>
<p class="xmsonormal">var jshell = JShell.create() ;</p>
<p class="xmsonormal">jshell.sourceCodeAnalysis().analyzeCompletion("println(").source() // null</p>
<p class="xmsonormal">```</p>
<p class="xmsonormal">this second line returns null, but the doc of SourceCodeAnalysis.CompletionInfo#source() says this:</p>
<p class="xmsonormal">```</p>
<div style="margin-right:7.5pt;margin-bottom:3.75pt;font-variant-ligatures:normal;font-variant-caps:normal;orphans:2;widows:2;text-decoration-style:initial;text-decoration-color:initial;word-spacing:0px">
<p class="xmsonormal"><span style="font-size:10.5pt">Source code for the first Snippet of code input. For example, first statement, or first method declaration. Trailing semicolons will be added, as needed.</span></p>
</div>
<p class="xmsonormal" style="margin-top:7.5pt"><b><span style="font-size:9.0pt;color:#353833">Returns:</span></b></p>
<p class="xmsonormal" style="mso-margin-top-alt:0cm;margin-right:7.5pt;margin-bottom:7.5pt;margin-left:36.0pt">
<span style="font-size:10.5pt;color:#353833">the source of the first encountered Snippet</span></p>
<p class="xmsonormal" style="mso-margin-top-alt:0cm;margin-right:7.5pt;margin-bottom:7.5pt;margin-left:0cm">
<span style="font-size:10.5pt;color:#353833">```</span></p>
<p class="xmsonormal" style="mso-margin-top-alt:0cm;margin-right:7.5pt;margin-bottom:7.5pt;margin-left:0cm">
There is no mention that it can return null.</p>
<p class="xmsonormal" style="mso-margin-top-alt:0cm;margin-right:7.5pt;margin-bottom:7.5pt;margin-left:0cm">
Yes it can makes sense to return null (well actually yesn’t since from what I’ve seen from the source code, it’s only null if it is incomplete, it’s not null even if it is unknown), since I gave an invalid snippet, but the doc should at least mention it.</p>
<p class="xmsonormal" style="mso-margin-top-alt:0cm;margin-right:7.5pt;margin-bottom:7.5pt;margin-left:0cm">
 </p>
<p class="xmsonormal" style="mso-margin-top-alt:0cm;margin-right:7.5pt;margin-bottom:7.5pt;margin-left:0cm">
Regards,</p>
<p class="xmsonormal" style="mso-margin-top-alt:0cm;margin-right:7.5pt;margin-bottom:7.5pt;margin-left:0cm">
Tom.</p>
<p class="xmsonormal"> </p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</body>
</html>