vscode-java: Corrupted workspace state on restart
Every so often, when I close VS Code and I open it again later to continue working on the project, the Java Language Server (or some part of this extension) gets a corrupted build state. All my Java files get red-lined everywhere especially with imports (which should have been resolved correctly through Maven dependencies). It makes the entire Java project riddled with errors, when there should be 0 errors reported.
The workspace log file reports:
message: The project was not built since the source file /jdt.ls-java-project/src/com/example/package/SampleClass-6b2da599__18012WV3rlaskH3xV.java could not be read;code: 0
It looks like some kind of weird diff version of the original class file (perhaps generated from all the diffing I do while I work on my project. Looks like JLS thinks the diff file is an actual project file and keeps looking for it?
I tried to look inside this jdt.ls-java-project
folder but I have no idea what’s wrong. The file doesn’t exist. I don’t know how to fix this or how to force refresh JLS cache (if there’s such a thing). Any hints and pointers will be very helpful. This is the second time I am getting this problem; I don’t remember how I fixed it the first time or it just fixed itself somehow.
Environment
- Operating System: Windows 10 x64
- JDK version: 1.8.0_144
- Visual Studio Code version: 1.18.1
- Java extension version: 0.15.0
Steps To Reproduce
I’m not really sure. It just randomly happens when I close VS Code and open it later again.
Current Result
Weird build errors resulting in red-lining throughout the project.
Expected Result
Successfully built project every time.
Additional Information
None.
About this issue
- Original URL
- State: open
- Created 7 years ago
- Reactions: 2
- Comments: 32 (2 by maintainers)
@MattJakeman I can’t investigate further until I manage to reproduce the issue. Until then, the best remedy is to delete the vscode workspace directory and try again
Never mind got it C:\Users\USERNAME\AppData\Roaming\Code\User\workspaceStorage
https://github.com/redhat-developer/vscode-java/wiki/Troubleshooting#clean-the-workspace-directory
@ADTC Thanks for the tip. I tried that but it didn’t work for me. It does it in every project I have as well so it’s making it almost unusable at the moment. @fbricon I’ve tried moving the project directory to no avail. There are only about 5 classes in one of the projects and I see the same behaviour. One of the projects has been worked on on another machine (mac) previously and suffered no issues. However, at that time it was running perfectly fine for me as well.
I’ve seen this issue pop up several times, randomly, but haven’t found the cause of the m2e plugin failing to start yet. We need to investigate.
So I found this XML file
.project
underC:\Users\ADTC\AppData\Roaming\Code\User\workspaceStorage\80cb5f2a3ecedacc12fe324f7ee7b83d\redhat.java\jdt_ws\jdt.ls-java-project
and it has this tag called<linkedResources>
. It goes a little something like this:I have no idea what this is or how it got there, but I removed the whole
<linkedResources>
tag and that resolved the problem somehow. I did an “Update project configuration” and then “Force Java compilation > Full” and a couple of restart/reload and it seems to have gone away.What is creating these unnecessary links in the
.project
XML file?