[JShell] SourceCodeAnalysis.CompletionInfo#source() can be null but the doc doesn't say anything about it

tom L tom_L64 at hotmail.com
Mon Oct 23 18:26:11 UTC 2023


Hello,
I have a problem with JShell, I don’t know if it should go in this mailing list.
On JDK 21 (should be the same for any JDK version 9+), Windows 11, with this following code :
```
var jshell = JShell.create() ;
jshell.sourceCodeAnalysis().analyzeCompletion("println(").source() // null
```
this second line returns null, but the doc of SourceCodeAnalysis.CompletionInfo#source() says this:
```
Source code for the first Snippet of code input. For example, first statement, or first method declaration. Trailing semicolons will be added, as needed.
Returns:
the source of the first encountered Snippet
```
There is no mention that it can return null.
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.

Regards,
Tom.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/core-libs-dev/attachments/20231023/baf89635/attachment.htm>


More information about the core-libs-dev mailing list