Please use the Apache issue tracking system for new NetBeans issues ( !!
Bug 267915 - [JShell] out of bounds during code completion
[JShell] out of bounds during code completion
Product: java
Classification: Unclassified
Component: JShell
PC Linux
: P2 (vote)
: Dev
Assigned To: Svata Dedic
Depends on:
  Show dependency treegraph
Reported: 2016-09-07 07:57 UTC by Jaroslav Tulach
Modified: 2016-12-01 13:48 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT

Possible fix (4.77 KB, patch)
2016-09-08 12:53 UTC, Svata Dedic
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jaroslav Tulach 2016-09-07 07:57:53 UTC
Get project (revision fb88ee6fd5d0a3050e11e5d083eb72a89c7e1496) and open it in JShell enabled NetBeans (changeset 2820788ce2ce in my case). Execute it. The JShell console is opened in editor. Try to type (possibly using code completion):

Exports.createServer((p1, p2) -> {

now place the cursor behind "p1." and press Ctrl+Space. Following exception is thrown:

java.lang.StringIndexOutOfBoundsException: String index out of range: -1023
	at java.lang.String.substring(
	at org.netbeans.modules.parsing.impl.TaskProcessor.callUserTask(
	at org.netbeans.modules.parsing.api.ParserManager$
	at org.netbeans.modules.parsing.api.ParserManager$
	at org.netbeans.modules.parsing.impl.TaskProcessor$
	at org.netbeans.modules.parsing.impl.TaskProcessor$
	at org.netbeans.modules.masterfs.filebasedfs.utils.FileChangedManager.priorityIO(
	at org.netbeans.modules.masterfs.providers.ProvidedExtensions.priorityIO(
	at org.netbeans.modules.parsing.nb.DataObjectEnvFactory.runPriorityIO(
	at org.netbeans.modules.parsing.impl.Utilities.runPriorityIO(
	at org.netbeans.modules.parsing.impl.TaskProcessor.runUserTask(
Caused: org.netbeans.modules.parsing.spi.ParseException
	at org.netbeans.modules.parsing.impl.TaskProcessor.runUserTask(
	at org.netbeans.modules.parsing.api.ParserManager.parse(
[catch] at$JavaCompletionQuery.query(
	at org.openide.util.RequestProcessor$
	at org.netbeans.modules.openide.util.GlobalLookup.execute(
	at org.openide.util.lookup.Lookups.executeWith(
	at org.openide.util.RequestProcessor$
Comment 1 Jaroslav Tulach 2016-09-07 07:59:22 UTC
If we could start the server, it would form nice JavaOne demo.
Comment 2 Svata Dedic 2016-09-08 12:51:47 UTC
I have fixed the issue in jshell_support_jdk9 branch. The implementation used caret position to navigate or offset within the parsing API Snapshot - in the case the snapshot contains an embedding of only part of the source, deltas / lengths screw up.

Please review the attached diff.
Comment 3 Svata Dedic 2016-09-08 12:53:21 UTC
Created attachment 161971 [details]
Possible fix

I have added helper methods to translate caret position to pos in the embedding; IMHO they should be protected for other BaseTask subclasses, but it's not the right time to do API changes if the patch could make it to 8.2 release
Comment 4 Dusan Balek 2016-09-08 14:01:49 UTC
The proposed fix looks OK except of the spec.version.base change from 1.7.0 to 1.6.0. I would also consider making the helper methods protected right now even though it requires an API change.
Comment 5 Svata Dedic 2016-10-07 08:47:40 UTC
Moving to an appropriate component
Comment 6 Svata Dedic 2016-12-01 13:48:55 UTC
Should be already fixed by rewriting the parsing/embedding creation.

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2014, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo