Vscode-java: Problem with codeComplete when typing "HashMap" in package-less classes

Created on 17 Mar 2017  Â·  39Comments  Â·  Source: redhat-developer/vscode-java

Java Language Support produces the following error message in the output pane whenever I start typing HashMap.

[Error - 11:09:35 am] 17/03/2017 10:53:22 AM Problem with codeComplete for
String index out of range: -1
java.lang.StringIndexOutOfBoundsException: String index out of range: -1
    at java.lang.String.<init>(String.java:196)
    at org.eclipse.jdt.ls.core.internal.contentassist.CompletionProposalDescriptionProvider.createTypeProposalLabel(CompletionProposalDescriptionProvider.java:400)
    at org.eclipse.jdt.ls.core.internal.contentassist.CompletionProposalDescriptionProvider.createTypeProposalLabel(CompletionProposalDescriptionProvider.java:379)
    at org.eclipse.jdt.ls.core.internal.contentassist.CompletionProposalDescriptionProvider.updateDescription(CompletionProposalDescriptionProvider.java:583)
    at org.eclipse.jdt.ls.core.internal.contentassist.CompletionProposalRequestor.toCompletionItem(CompletionProposalRequestor.java:68)
    at org.eclipse.jdt.ls.core.internal.contentassist.CompletionProposalRequestor.getCompletionItems(CompletionProposalRequestor.java:54)
    at org.eclipse.jdt.ls.core.internal.handlers.CompletionHandler.computeContentAssist(CompletionHandler.java:80)
    at org.eclipse.jdt.ls.core.internal.handlers.CompletionHandler.lambda$0(CompletionHandler.java:39)
    at java.util.concurrent.CompletableFuture.uniApply(CompletableFuture.java:602)
    at java.util.concurrent.CompletableFuture$UniApply.tryFire(CompletableFuture.java:577)
    at java.util.concurrent.CompletableFuture$Completion.exec(CompletableFuture.java:443)
    at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
    at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
    at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
    at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)

Environment
  • Operating System: Windows 10
  • JDK version: 8.91
  • Visual Studio Code version: 1.10.2
  • Java extension version: 0.0.12
Steps To Reproduce
  1. Start typing "HashMap"
bug content-assist

All 39 comments

Did you see this behaviour before?
Does it happen for other types?
Can you reproduce with a simple class/project?

This behaviour started when I updated the Java Language Support Extension.

Also happens when typing "for" with the following error message:

[Error - 11:21:42 am] 17/03/2017 10:53:22 AM Problem with codeComplete for file:///<<FILE PATH HERE>>/Reader.java
String index out of range: -1
java.lang.StringIndexOutOfBoundsException: String index out of range: -1
    at java.lang.String.<init>(String.java:196)
    at org.eclipse.jdt.ls.core.internal.contentassist.CompletionProposalDescriptionProvider.createTypeProposalLabel(CompletionProposalDescriptionProvider.java:400)
    at org.eclipse.jdt.ls.core.internal.contentassist.CompletionProposalDescriptionProvider.createTypeProposalLabel(CompletionProposalDescriptionProvider.java:379)
    at org.eclipse.jdt.ls.core.internal.contentassist.CompletionProposalDescriptionProvider.updateDescription(CompletionProposalDescriptionProvider.java:583)
    at org.eclipse.jdt.ls.core.internal.contentassist.CompletionProposalRequestor.toCompletionItem(CompletionProposalRequestor.java:68)
    at org.eclipse.jdt.ls.core.internal.contentassist.CompletionProposalRequestor.getCompletionItems(CompletionProposalRequestor.java:54)
    at org.eclipse.jdt.ls.core.internal.handlers.CompletionHandler.computeContentAssist(CompletionHandler.java:80)
    at org.eclipse.jdt.ls.core.internal.handlers.CompletionHandler.lambda$0(CompletionHandler.java:39)
    at java.util.concurrent.CompletableFuture.uniApply(CompletableFuture.java:602)
    at java.util.concurrent.CompletableFuture$UniApply.tryFire(CompletableFuture.java:577)
    at java.util.concurrent.CompletableFuture$Completion.exec(CompletableFuture.java:443)
    at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
    at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
    at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
    at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)

I also recently uninstalled Visual Studio 2017 Community. Could that have caused this issue?

I just tried a new simple class to see if the error would still occur.
This time it happened when I started typing "String" with the following error message:

[Error - 11:27:37 am] 17/03/2017 11:26:25 AM Problem with codeComplete for file:///c%3A/Users/aaron/OneDrive/Temp/Test.java
String index out of range: -1
java.lang.StringIndexOutOfBoundsException: String index out of range: -1
    at java.lang.String.<init>(String.java:196)
    at org.eclipse.jdt.ls.core.internal.contentassist.CompletionProposalDescriptionProvider.createTypeProposalLabel(CompletionProposalDescriptionProvider.java:400)
    at org.eclipse.jdt.ls.core.internal.contentassist.CompletionProposalDescriptionProvider.createTypeProposalLabel(CompletionProposalDescriptionProvider.java:379)
    at org.eclipse.jdt.ls.core.internal.contentassist.CompletionProposalDescriptionProvider.updateDescription(CompletionProposalDescriptionProvider.java:583)
    at org.eclipse.jdt.ls.core.internal.contentassist.CompletionProposalRequestor.toCompletionItem(CompletionProposalRequestor.java:68)
    at org.eclipse.jdt.ls.core.internal.contentassist.CompletionProposalRequestor.getCompletionItems(CompletionProposalRequestor.java:54)
    at org.eclipse.jdt.ls.core.internal.handlers.CompletionHandler.computeContentAssist(CompletionHandler.java:80)
    at org.eclipse.jdt.ls.core.internal.handlers.CompletionHandler.lambda$0(CompletionHandler.java:39)
    at java.util.concurrent.CompletableFuture.uniApply(CompletableFuture.java:602)
    at java.util.concurrent.CompletableFuture$UniApply.tryFire(CompletableFuture.java:577)
    at java.util.concurrent.CompletableFuture$Completion.exec(CompletableFuture.java:443)
    at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
    at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
    at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
    at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)

Can you set the java.trace.server setting to verbose, and attach the logs here please?

Here are the logs. The error that I mention is logged at line number 15283.
JavaLogs.txt

Looks like the issue is could be with my Classpath. I had a look at the settings and found that this error was being suppressed: "Classpath is incomplete. Only syntax errors will be reported".

I have the same problem. Seems to happen randomly every 5-10 minutes at most. Adding a pom.xml file didn't help, this started with 0.12 and has made the extension unusable for me...

There was a severe regression in the Java Language server (eclipse/eclipse.jdt.ls#191) used in vscode-java 0.0.12. We released a fix with 0.0.13. Please update your vscode java extension

I too am having the idendential error with code completion, running on Ubuntu 16.04. The issue occurs whenever I start typing anything on a new line.

Updating to 0.0.13 didn't help, got the issue again just this morning after updating and restarting.

Please try deleting %APPDATA%\Code\User\workspaceStorage (or ~/Library/Application Support/Code/User/workspaceStorage on MacOS) and restart vscode

The problem seems to persist still for me.

I solved my issue: the extension automatically generated some project files when I was still using 0.0.12, removing them fixed the problem.

@Aaron216 @james-black do you guys still see the issue or can we close this ticket ?

The issue seems to be resolved for me

Updating to 0.0.13 did not resolve the issue.
Deleting files in %APPDATA%\Code\User\workspaceStorage seems to have fixed it though.
Feel free to close the ticket.

Thank you for your help.

Ubuntu 16.04 here, unfortunately this problem still persists, it occurs when i start typing String or (sometimes) something else...i've already removed workspaceStorage folder, uninstall/install plugin, but nothing happens
@matrl0 what files you removed?

I started experiencing this issue again too.
I have now re-installed VS code and the Java Support extension but the issue persists.

Sorry, but we can't reproduce this issue so this makes it very hard to troubleshoot.
So, can you please attach your zipped workspace here, as well as the project including whatever eclipse files were generated?

Another thing you guys can try, after deleting the workspace storage, you can also delete the project .project, .classpath and settings ressources

Hi @fbricon, can you be a little bit more specific? Do you mean workspaceStorage folder?
where .project and .classpath are located?

Sorry for dumb questions

I'm also getting this error on Arch Linux 64-bit. Latest extension version and Visual Studio code version.

obviously the problem is in the FindSimpleNameSmart method in this file:
https://github.com/eclipse/eclipse.jdt.ls/blob/master/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/contentassist/CompletionProposalDescriptionProvider.java#L422

The fullName array either has: Nothing in it, A < symbol before a period or no periods.

I have the same issue. Here are the logs, this error occurs whenever the autocomplete recommendations dropdown appears (pretty much all the time).

[Error - 11:39:22] 26.3.2017 11:35:49 Problem with codeComplete for file:///m%3A/Documents/FRI%202.%20letnik%202016-17/APS-2/Naloga1/src/Naloga1.java
String index out of range: -1
java.lang.StringIndexOutOfBoundsException: String index out of range: -1
    at java.lang.String.<init>(String.java:196)
    at org.eclipse.jdt.ls.core.internal.contentassist.CompletionProposalDescriptionProvider.createTypeProposalLabel(CompletionProposalDescriptionProvider.java:400)
    at org.eclipse.jdt.ls.core.internal.contentassist.CompletionProposalDescriptionProvider.createTypeProposalLabel(CompletionProposalDescriptionProvider.java:379)
    at org.eclipse.jdt.ls.core.internal.contentassist.CompletionProposalDescriptionProvider.updateDescription(CompletionProposalDescriptionProvider.java:583)
    at org.eclipse.jdt.ls.core.internal.contentassist.CompletionProposalRequestor.toCompletionItem(CompletionProposalRequestor.java:68)
    at org.eclipse.jdt.ls.core.internal.contentassist.CompletionProposalRequestor.getCompletionItems(CompletionProposalRequestor.java:54)
    at org.eclipse.jdt.ls.core.internal.handlers.CompletionHandler.computeContentAssist(CompletionHandler.java:80)
    at org.eclipse.jdt.ls.core.internal.handlers.CompletionHandler.lambda$0(CompletionHandler.java:39)
    at java.util.concurrent.CompletableFuture.uniApply(CompletableFuture.java:602)
    at java.util.concurrent.CompletableFuture$UniApply.tryFire(CompletableFuture.java:577)
    at java.util.concurrent.CompletableFuture$Completion.exec(CompletableFuture.java:443)
    at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
    at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
    at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
    at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)

Hmm, I wonder if the issue has something to do with having spaces in the path.

I'm not sure if this is a related issue, but I recently noticed that I had not set the classpath variable. The following error would appear whenever the Java Language Sever started.

Classpath is incomplete. Only syntax errors will be reported

I have now attempted to set the "java.home" variable in VS code as follows.
"java.home":"C:\Program Files\Java\jdk1.8.0_91"
The above line is highlighted as an error in my settings.json file with the following error.

Invalid escape character in string

I believe the invalid character is "\" as when I remove all of the slashes, the warning goes away.
Though, I don't know how I'm meant to set a file path without using a slash character.
If I leave the slashes in the file path and ignore the syntax warning when I open VS code the following errors now appear whenever the Java Language Server attempts to start.

Couldn't start client Language Support for Java
The java.home variable defined in VS Code settings points to a missing folder

Hopefully, this is a simple error that I've made in setting up my environment.
Please let me know if there's an easy way to resolve this.

@Aaron216 Try replacing the \ in the path with \\

@hcorion Thanks. That's fixed the "Invalid escape character in string" warning and the "Couldn't start client Language Support for Java. The java.home variable defined in VS Code settings points to a missing folder" error that I was seeing at start-up.

But the "Classpath is incomplete. Only syntax errors will be reported" warning has returned whenever the Java Language Server starts.

I'm getting this error as well, Elementary OS 0.4 Loki, which is built on Ubuntu 16.04. Latest VS Code version and extension version. It happens whenever the code completion engine starts, which as was said before, is all the time. What could I do to help solve this faster?

@rugglcon Does the path the java file is in contain any spaces, > symbols or . symbols?

Yes it does.
On Mon, Mar 27, 2017 at 20:00 Zion notifications@github.com wrote:

@rugglcon https://github.com/rugglcon Does the path the java file is in
contain any spaces, > symbols or . symbols?

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/redhat-developer/vscode-java/issues/166#issuecomment-289629549,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ANp3MmXQSDPw0N5MsS0MC8M5x1Gzkdvyks5rqFm3gaJpZM4MgIUZ
.

@fbricon
Allright, here is the trace log:
https://pastebin.com/HPKk4BvN
To reproduce this, open a file called test.java, and copy-paste the following text:

import java.util.ArrayList;
public class test
{
  public ArrayList<>
}

And to crash it, just add a S between <> just like you were going to type String

@hcorion excellent, I could reproduce the error. I'll investigate tomorrow

This is caused by the project containing classes in the default package. The jdt.ls server doesn't check for that case in createTypeProposalLabel(char[] fullName, CompletionItem item), when appending the package separator

Deleting classes located at C:\Program Files\Java\Classes and removing that path from my CLASSPATH system variable appears to have resolved the issue.

Anyone willing to try a CI build of the fix, can download http://download.jboss.org/jbosstools/jdt.ls/staging/java-0.1.0.vsix and install it by following the instructions here.

Sorry but our latest build is broken at this time. If the java extension never downloads the java language server, then

Same error. Pops up only when I'm like writing invalid code in the .java file.
The problem for me not that error appears (since well if it's not sure that file is like being just written from the scratch) but that output pops up, it's kinda annoying.

Overall great plugin guys!

@idchlife can you paste your logs? Need to check if it's the exact same trace. Are you using the latest version?

@fbricon actually I had some kind of same error, but now I'm having only one and it differs:

[Error - 00:22:30] Sep 14, 2017 6:51:43 PM 
null
org.eclipse.jface.text.BadLocationException
    at org.eclipse.jface.text.TreeLineTracker.fail(TreeLineTracker.java:1051)
    at org.eclipse.jface.text.TreeLineTracker.lineByOffset(TreeLineTracker.java:265)
    at org.eclipse.jface.text.TreeLineTracker.getLineNumberOfOffset(TreeLineTracker.java:1119)
    at org.eclipse.jface.text.AbstractLineTracker.getLineNumberOfOffset(AbstractLineTracker.java:151)
    at org.eclipse.jface.text.AbstractDocument.getLineOfOffset(AbstractDocument.java:868)
    at org.eclipse.core.internal.filebuffers.SynchronizableDocument.getLineOfOffset(SynchronizableDocument.java:331)
    at org.eclipse.jdt.ls.core.internal.handlers.JsonRpcHelpers.toLine(JsonRpcHelpers.java:57)
    at org.eclipse.jdt.ls.core.internal.JDTUtils.toRange(JDTUtils.java:402)
    at org.eclipse.jdt.ls.core.internal.JDTUtils.toLocation(JDTUtils.java:338)
    at org.eclipse.jdt.ls.core.internal.JDTUtils.toLocation(JDTUtils.java:300)
    at org.eclipse.jdt.ls.core.internal.handlers.DocumentSymbolHandler.collectChildren(DocumentSymbolHandler.java:76)
    at org.eclipse.jdt.ls.core.internal.handlers.DocumentSymbolHandler.collectChildren(DocumentSymbolHandler.java:68)
    at org.eclipse.jdt.ls.core.internal.handlers.DocumentSymbolHandler.getOutline(DocumentSymbolHandler.java:52)
    at org.eclipse.jdt.ls.core.internal.handlers.DocumentSymbolHandler.documentSymbol(DocumentSymbolHandler.java:44)
    at org.eclipse.jdt.ls.core.internal.handlers.JDTLanguageServer.lambda$9(JDTLanguageServer.java:319)
    at java.util.concurrent.CompletableFuture.uniApply(CompletableFuture.java:602)
    at java.util.concurrent.CompletableFuture$UniApply.tryFire(CompletableFuture.java:577)
    at java.util.concurrent.CompletableFuture$Completion.exec(CompletableFuture.java:443)
    at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
    at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
    at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
    at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)


Was this page helpful?
0 / 5 - 0 ratings

Related issues

protoEvangelion picture protoEvangelion  Â·  3Comments

larixer picture larixer  Â·  3Comments

BuZZ-dEE picture BuZZ-dEE  Â·  4Comments

zalcorshark picture zalcorshark  Â·  3Comments

sfariaNG picture sfariaNG  Â·  3Comments