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-r...@openjdk.org> de la part de tom L 
<tom_...@hotmail.com>
Envoyé : Monday, October 23, 2023 8:26:11 PM
À : core-libs-dev@openjdk.org <core-libs-dev@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.



Reply via email to