RE : [JShell] SourceCodeAnalysis.CompletionInfo documentation is really vague
tom L
tom_L64 at hotmail.com
Wed Nov 8 20:01:26 UTC 2023
Hello,
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
Now, I also noticed that with this specific code, source and remaining are nearly equal
```
import jdk.jshell.*;
var shell = JShell.create()
var completion = shell.sourceCodeAnalysis().analyzeCompletion("while(true)")
println(completion.source()) // "while(true);"
println(completion.remaining()) // "while(true)\n"
```
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.
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.
Regards,
Tom.
De : core-libs-dev <core-libs-dev-retn at openjdk.org> de la part de tom L <tom_L64 at hotmail.com>
Envoyé : Monday, October 23, 2023 8:26:11 PM
À : core-libs-dev at openjdk.org <core-libs-dev at openjdk.org>
Objet : [JShell] SourceCodeAnalysis.CompletionInfo#source() can be null but the doc doesn't say anything about it
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/20231108/4b160e96/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: B61A568C0FC9409ABE94A994F1D90140.png
Type: image/png
Size: 144 bytes
Desc: B61A568C0FC9409ABE94A994F1D90140.png
URL: <https://mail.openjdk.org/pipermail/core-libs-dev/attachments/20231108/4b160e96/B61A568C0FC9409ABE94A994F1D90140.png>
More information about the core-libs-dev
mailing list