Bug 267915 - [JShell] out of bounds during code completion
[JShell] out of bounds during code completion
Status: RESOLVED FIXED
Product: java
Classification: Unclassified
Component: JShell
8.2
PC Linux
: P2 (vote)
: Dev
Assigned To: Svata Dedic
issues@java
:
Depends on:
Blocks:
  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
:


Attachments
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 https://github.com/jtulach/node4j 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):

import net.java.html.lib.node.http.Exports;
Exports.createServer((p1, p2) -> {
    p1.
})

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(String.java:1967)
	at org.netbeans.modules.java.completion.BaseTask.getEnvImpl(BaseTask.java:369)
	at org.netbeans.modules.java.completion.BaseTask.getCompletionEnvironment(BaseTask.java:266)
	at org.netbeans.modules.java.completion.JavaCompletionTask.resolve(JavaCompletionTask.java:269)
	at org.netbeans.modules.java.completion.BaseTask.run(BaseTask.java:93)
	at org.netbeans.modules.java.completion.JavaCompletionTask.run(JavaCompletionTask.java:80)
	at org.netbeans.modules.parsing.impl.TaskProcessor.callUserTask(TaskProcessor.java:609)
	at org.netbeans.modules.parsing.api.ParserManager$UserTaskAction.run(ParserManager.java:153)
	at org.netbeans.modules.parsing.api.ParserManager$UserTaskAction.run(ParserManager.java:137)
	at org.netbeans.modules.parsing.impl.TaskProcessor$2.call(TaskProcessor.java:204)
	at org.netbeans.modules.parsing.impl.TaskProcessor$2.call(TaskProcessor.java:201)
	at org.netbeans.modules.masterfs.filebasedfs.utils.FileChangedManager.priorityIO(FileChangedManager.java:176)
	at org.netbeans.modules.masterfs.providers.ProvidedExtensions.priorityIO(ProvidedExtensions.java:360)
	at org.netbeans.modules.parsing.nb.DataObjectEnvFactory.runPriorityIO(DataObjectEnvFactory.java:141)
	at org.netbeans.modules.parsing.impl.Utilities.runPriorityIO(Utilities.java:88)
	at org.netbeans.modules.parsing.impl.TaskProcessor.runUserTask(TaskProcessor.java:201)
Caused: org.netbeans.modules.parsing.spi.ParseException
	at org.netbeans.modules.parsing.impl.TaskProcessor.runUserTask(TaskProcessor.java:209)
	at org.netbeans.modules.parsing.api.ParserManager.parse(ParserManager.java:104)
[catch] at org.netbeans.modules.editor.java.JavaCompletionProvider$JavaCompletionQuery.query(JavaCompletionProvider.java:234)
	at org.netbeans.spi.editor.completion.support.AsyncCompletionTask.run(AsyncCompletionTask.java:223)
	at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:1443)
	at org.netbeans.modules.openide.util.GlobalLookup.execute(GlobalLookup.java:68)
	at org.openide.util.lookup.Lookups.executeWith(Lookups.java:303)
	at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:2058)
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